[]
        
(Showing Draft Content)

Create Views in PivotEngine

The PivotEngine class has a simple and powerful object model that allows you to create, edit, and persist views programmatically.

To create views, follow these steps:

  1. Set the engine's itemsSource property and let it create the fields automatically, or create the fields in code.
  2. Copy one or more dimension fields from the fields collection to the rowFields or colunmFields collections.
  3. Copy one or more measure fields from the fields collection to the valueFields collection.

Get Answers

Views are designed to answer questions. Let's pretend we have data about people and items that they purchase at a store. Our data may have the following fields...

{
    date, // date of purchase
    Person, // person who bought
    Category, // type of item bought
    Amount // price spent by buyer
}
  • How much was spent by each person?

To answer this question, we can add the 'Amount' to the valueFields list and add 'Person' to the rowFields list.

ng.valueFields.push('Amount');
ng.rowFields.push('Person');

How might you answer the following questions using the technique above?

  • How much was spent on each expense type?
  • What did each person spend money on?
  • When were these expenses made?

Edit and Persist Views

Once you have created one or more views, you can use a PivotPanel control to allow users to edit them, and you can use the PivotEngine.viewDefinition property to convert view definitions to strings to you can save and restore them easily.