Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
pivot grid data source
posted

is there any sample code for binding an arbitrary collection of objects to the pivot grid.  For example, I dont want to go through RIA to connect to the server, I just want to report on a collection of data I have.  The following code does not work:

 

 

 

 

public

 

 

class Data

{

 

 

 

public DateTime Date { get; set; }

 

 

 

public string Ticker {get;set;}

 

 

 

public double Value { get; set; }

}

 

 

 

 

 

 

List

 

 

<Data> data = new List<Data>();

data.Add(

 

new Data{

Date =

 

DateTime.Parse("1/1/2000"),

Ticker =

 

"IBM",

Value = 1.0

});

 

 

this.xamPivotGrid1.DataSource = data;

It wants an instance of IOlapViewModel

 

Thanks in advance

 

 

 

 

 

Parents
  • 7922
    Verified Answer
    posted

    Hi

     

    To provide data to XamPivotGrid you should create DataSource that XamPivotGrid can read. Such oblects are  FlatDataSource and  XmlaDataSource. The first type is used when you have IEnumerable and want to show this data in the grid. The second type is used when you have analysis server as MS SQL Analysis server 2008.  In your case you should FlatDataSource. Below is the code you can use to provide your data:

     

    List<Data> data = new List<Data>();

    data.Add(new Data

    {

        Date = DateTime.Parse("1/1/2000"),

        Ticker = "IBM",

        Value = 1.0

    });

     

     

    FlatDataSource flatDataSource = new FlatDataSource

        {

            ItemsSource = data,

            Cube = DataSourceBase.GenerateInitialCube("Data"),

            Rows = DataSourceBase.GenerateInitialItems("[Date]"),

            Columns = DataSourceBase.GenerateInitialItems("[Ticker]"),

            Measures = DataSourceBase.GenerateInitialItems("Value")

        };

     

    pivotGrid.DataSource = flatDataSource;

     

    The cube is your class that contains properties with data – here is “Data”. For rows and columns you should provide properties whose data will be shown in rows or in column and for measure you provide property with data for cells. Finally you have to assign XamPivotGrid’s DataSource samples. In addition you can use HierarchyDescriptor<Data>  to customize the look of the data in rows, columns and cell. You can see more complex sample about HierarchyDescriptor here http://labs.infragistics.com/silverlightdv/2010.2/#/Samples/PivotGrid/Basic/DataSourceFlatDataCB

    Regards 

    Todor 

Reply Children