Like your newly released version of the xamgrid I would love to be able to use string indexers for measures within the xampivotgrid (which is great BTW and was desperately needed).
Is there anyway to manually add measures for the flatdatasource that would allow the pivotgrid to display data from a collection of data on a data class?
Thanks in advance for any tips.
Doug
Hi Doug,
The flatdatasource is designed to work with table structured data. This means that it analyze data row by row and is not predicted to analyze relational data.
I will give you a sample. If you have 3 tables in your database: Seller, Product and Sale, you have to make a view on these 3 tables and join them together. After that you put the view to the flatdatasource for analyst.
If you describe your case in more details may be I will be able to give you a more specific advice.
Regards
Todor
Hi Todor,
Basically I have a class called Product which has a collection of store numeric values. I want to be able to display the list of store names as measures so the users can display sum totals etc for each store numeric value against the list of products. If my Product class has a public property for each store, then it is easy and I can already get that working, but I dont really want a public property for the store but rather just a dictionary of all the store names and their values.
Regards,Doug
So I seem to have it working to a basic level using the following code. But what I need to be able to do is add other values under the Product list such as colours, departments etc, not just categories. Do I need to add them as dimensionsettings or as hierarchies?
I have to say the help files and samples are not really detailed enough for this powerful control. Do you have plans to create more detailed help on this control?
Thanks,Doug
var pivotData = BuySheetPrototype1.PivotData.PivotDataGenerator.GenerateBuys(source);
FlatDataSource flatDataSource = new FlatDataSource(){ ItemsSource = pivotData, Cube = DataSourceBase.GenerateInitialCube("ItemBuy"), Rows = DataSourceBase.GenerateInitialItems("[Product]"), Columns = DataSourceBase.GenerateInitialItems("[Store]"), Measures = DataSourceBase.GenerateInitialItems("NumberOfUnits")};
CubeMetadata cubeMetadata = new CubeMetadata();cubeMetadata.DisplayName = "Buy Data";cubeMetadata.DataTypeFullName = typeof(BuySheetPrototype1.PivotData.ItemBuy).FullName; cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "NumberOfUnits", DisplayName = "Number of Units", DisplayFormat = "{0:N0}"});
cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "RetailAmount", DisplayName = "Retail Amount", DisplayFormat = "{0:N0}"});cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "Product", DisplayName = "Product", AutoGenerateField=true}); cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "Store", DisplayName = "Store"}); flatDataSource.CubesSettings.Add(cubeMetadata);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> sellerHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Store);sellerHierarchy.AddLevel(p => "All Stores", "All Stores");sellerHierarchy.AddLevel(p => p.Store.StoreName, "Store Name");flatDataSource.AddHierarchyDescriptor(sellerHierarchy);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> categoryHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product);categoryHierarchy.AddLevel(p => "All Categories", "All Categories");categoryHierarchy.AddLevel(p => p.Product.Category, "Category");flatDataSource.AddHierarchyDescriptor(categoryHierarchy);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> colourHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product.Colour);colourHierarchy.AddLevel(p => "All Colours", "All Colours");colourHierarchy.AddLevel(p => p.Product.Colour, "Colour");flatDataSource.AddHierarchyDescriptor(colourHierarchy);
this.pivotGrid.DataSource = flatDataSource;this.dataSelector.DataSource = flatDataSource;
public class ItemBuy{ public ItemBuy() { Product = new Product(); Store = new Store(); }
public Product Product { get; set; } public Store Store { get; set; }
public int NumberOfUnits { get; set; }
public decimal RetailAmount { get { return Product.Retail_Price * NumberOfUnits; } set { Product.Retail_Price = value / NumberOfUnits; } }}
public class Product{ public string Category { get; set; } public string Style_Description { get; set; } public string Colour { get; set; } public string Department { get; set; } public string Division { get; set; } public decimal Retail_Price { get; set; }}
public class Store{ public string StoreName { get; set; }}
Hello,
Your last hierarchy descriptor is not applied because the lambda that you’re applying is for property that doesn’t belong to ItemBuy type.
I mean p => p.Product.Colour
Also are you sure that this line of code does not throw exception, because there is verification for declaring type of property to matches the type of generic parameter.
You may expose the color of Product as another property of ItemBuy and use it as additional dimension.
If it’s more appropriate for your needs you can add it as additional level of any of your hierarchies. The disadvantage is that you’ll see the color values after the upper level is expanded. For example:
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> categoryHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product);categoryHierarchy.AddLevel(p => "All Categories", "All Categories");categoryHierarchy.AddLevel(p => p.Product.Category, "Category");categoryHierarchy.AddLevel(p => p.Product.Color, "Colors");flatDataSource.AddHierarchyDescriptor(categoryHierarchy);
will produce additional level filled with all of colors found for given category.
Regards.
Plamen.
Hi Plamen,
You are right it did throw an exception. I had it commented out in my code for that reason.
I think I want to add it as another property of ItemBuy as another dimension. Would you mind showing me how to do that? I cant seem to get it working.
I dont really want the colours nested under the categories, just at the same level as categories are shown.
Thanks in advance,
Doug Rees
Polo Ralph Lauren
Adding it as property of ItemBuy
public string Color
{
get
return this.Product.Colour;
}
is enough for creation of another dimension.
I hope it helps.
That works. Ok thanks very much Plamen...