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
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
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 });
FlatDataSource flatDataSource = new FlatDataSource()
ItemsSource = panes,
Cube = DataSourceBase.GenerateInitialCube("Pane"),
Columns = DataSourceBase.GenerateInitialItems("[Price]"),
Rows = DataSourceBase.GenerateInitialItems("[Geography],[Product]"),
Measures = DataSourceBase.GenerateInitialItems("Value")
};
HierarchyDescriptor<Pane> ds = new HierarchyDescriptor<Pane>(p => p.Price);
ds.AddLevel(p => p.Price, "Prices");
ds.AddLevel(p => p.Units, "Units");
flatDataSource.AddHierarchyDescriptor(ds);
pivotGrid.DataSource = flatDataSource;
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 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.
The data source organized in such way, doesn’t have relation between the data. There is not information how many "Deodorants" are sold for "Household".
Your data should look like something like below:
public string Test { get; set; }
Fill your data:
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Rinse Conditioners", Value = 22 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Main Wash", Value = 33 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Deodorants", Value = 44 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Tumble Drying Enhancer", Value = 55 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Iron Enhancer", Value = 66 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Wash Treatmentr", Value = 77 });
panes.Add(new Pane { Geography = "Household", Test = "Unit Sales", Product = "Iron Enhancer", Value = 88 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Rinse Conditioners", Value = 12 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Main Wash", Value = 13 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Deodorants", Value = 14 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Tumble Drying Enhancer", Value = 15 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Iron Enhancer", Value = 16 });
panes.Add(new Pane { Geography = "Grocery Outlets", Test = "Unit Sales", Product = "Special Wash", Value = 17 });
And bind them to XamPivotGrid
Columns = DataSourceBase.GenerateInitialItems("[Geography]"),
Rows = DataSourceBase.GenerateInitialItems("[Product]"),
pivotSelector.DataSource = flatDataSource;
Hope this helps
Todor