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
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",
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
Pane
; }
And in Code Behind
pane = new Pane();
List<string> geography = new List<string>();
List<string> product = new List<string>();
List<string> unit = new List<string>();
List<string> valuePane = new List<string>();
geography.Add(
"Household");
"Grocery Outlets");
product.Add(
"Rinse Conditioners");
"Main Wash");
"Deodorants");
"Tumble Drying Enhancer");
"Iron Enhancer");
"Special Wash");
"Wash Treatment");
unit.Add(
"Unit Sales");
"Value Sales");
"Volume Sales");
valuePane.Add(
pane.Geography = geography;
pane.Product = product;
pane.Units = unit;
pane.Value = valuePane;
List<Pane> pn = new List<Pane>();
pn.Add(pane);
FlatDataSource flatDataSource = new FlatDataSource()
ItemsSource = pn,
Cube =
DataSourceBase.GenerateInitialCube("Geography"),
Rows =
DataSourceBase.GenerateInitialItems("Test"),
Measures =
DataSourceBase.GenerateInitialItems("Value)
pivotgrid.DataSource = flatDataSource;
pivotSelector.DataSource = flatDataSource;
But its displaying the Result as System.Collections.Generic.List. Its not displaying the actual data from the List.
Columns =
DataSourceBase.GenerateInitialItems("Product"),
Thank you so much for your kind response. Ya I know that this will work. But i wanted to know whether it will work or not if we pass ItemsSource object as List Which contains a List like what I mentioned in my previous post. Actually My requirement is as below. I want to do this.
This is what i want to display in my Pivot Grid.
There is a lot of variance to do the task
The first one is:
public class Pane
public string Geography { get; set; }
public string Product { get; set; }
public string Price { get; set; }
List<Pane> panes = new List<Pane>();
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price1", Product = "Rinse Conditioners", Value = 22 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price2", Product = "Main Wash", Value = 33 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price3", Product = "Deodorants", Value = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price1", Product = "Tumble Drying Enhancer", Value = 55 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price2", Product = "Iron Enhancer", Value = 66 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price3", Product = "Wash Treatmentr", Value = 77 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Units = "Price1", Product = "Iron Enhancer", Value = 88 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price1", Product = "Rinse Conditioners", Value = 12 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price2", Product = "Main Wash", Value = 13 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price3", Product = "Deodorants", Value = 14 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price1", Product = "Tumble Drying Enhancer", Value = 15 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price2", Product = "Iron Enhancer", Value = 16 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Units = "Price3", Product = "Special Wash", Value = 17 });
ItemsSource = panes,
Cube = DataSourceBase.GenerateInitialCube("Pane"),
Columns = DataSourceBase.GenerateInitialItems("[Price]"),
Rows = DataSourceBase.GenerateInitialItems("[Geography],[Product]"),
HierarchyDescriptor<Pane> ds = new HierarchyDescriptor<Pane>(p => p.Price);
ds.AddLevel(p => p.Price, "Prices");
ds.AddLevel(p => p.Units, "Units");
flatDataSource.AddHierarchyDescriptor(ds);
With adding HierarchyDescriptor you can define the hierarchy level. This code will produce the follow picture
2/ The second variant is:
If you don’t want totals you should change data source like bellow and don’t add hierarchy descriptor:
Columns = DataSourceBase.GenerateInitialItems("[Price],[Units]"),
This code produce the follow picture:
3/ the third variant is:
If you want each price to have different currency you should define 3 measures. And the code should be like this:
public double Price1 { get; set; }
public double Price2 { get; set; }
public double Price3 { get; set; }
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Rinse Conditioners", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Main Wash", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Deodorants", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Tumble Drying Enhancer", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Iron Enhancer", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Household", Price = "Price", Product = "Wash Treatmentr", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Rinse Conditioners", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Main Wash", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Deodorants", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Tumble Drying Enhancer", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Iron Enhancer", Price1 = 22, Price2 = 33, Price3 = 44 });
panes.Add(new Pane { Geography = "Grocery Outlets", Price = "Volume", Product = "Special Wash", Price1 = 22, Price2 = 33, Price3 = 44 });
Measures = DataSourceBase.GenerateInitialItems("Price1,Price2,Price3")
CubeMetadata cmd = new CubeMetadata { DataTypeFullName = typeof(Pane).FullName };
cmd.DimensionSettings.Add(new DimensionMetadata { DisplayName = "Price1", SourcePropertyName = "Price1", DisplayFormat = "${0}" });
cmd.DimensionSettings.Add(new DimensionMetadata { DisplayName = "Price2", SourcePropertyName = "Price2", DisplayFormat = "£{0}" });
cmd.DimensionSettings.Add(new DimensionMetadata { DisplayName = "Price3", SourcePropertyName = "Price3", DisplayFormat = "{0}" });
flatDataSource.CubesSettings.Add(cmd);
The result is below:
Thank you so much. This is what I wanted. I have one doubt in this, if I want to display the products as Measures then how it can be done?. Actually I have one string property named as 'Product" under Pane class. I would like to add this Product to Measures. I am not able to add string parameters to Measures.Then how to do Compact Layout like as below.
Hi,
Measures are created over measurable data only – this means that only properties with type of int, double and etc. are used when measure dimensions are generated.
You can create hierarchical structure over Pane.Geography property with second level based on Pane.Product property and that I think will produce the view you want.
HierarchyDescriptor<Pane> ds = new HierarchyDescriptor<Pane>(p => p.Geography);
ds.AddLevel(p => p.Geography, "Geography");
ds.AddLevel(p => p.Product, "Product");
pivotGrid.AllowCompactLayout = true;
Regards.
Plamen.
This works fine. Thank you. If I want to display 100000 of records then how about the performance. How to do pagination?