Essential Chart Business Intelligence
Syncronize a OlapChart with a PivotGrid
June 9, 2011 08:43 AM by Ganesan[Syncfusion]
Jorge Pampin
Syncronize a OlapChart with a PivotGrid
June 8, 2011 11:29 AM
Hello,

I'm trying to syncronize a OlapChart with a PivotGrid, it's similar to OlapClient. This is my code to generate the OlapReport,it is executed when there are some change in the OlapGrid:

OlapReport LoadFromDataTableCollection()
{
OlapReport olapReport = new OlapReport();

olapReport.ShowExpanders = true;
olapReport.ShowEmptyColumnData = true;
olapReport.ShowEmptyRowData = true;

MeasureElements meansureElements = new MeasureElements();


DimensionElement dimensionElementColumn = new DimensionElement();
dimensionElementColumn.Name = "dimensionElementColumn";
dimensionElementColumn.Hierarchy = new HierarchyElement() { Name = "dimensionElementColumn" };

foreach (PivotItem item in this.PGDatos.PivotColumns)
{
string Nombre = item.FieldMappingName;

dimensionElementColumn.Hierarchy.LevelElements.Add(new LevelElement() { Name = Nombre, DimensionName = item.FieldHeader });
}


DimensionElement dimensionElementRow = new DimensionElement();
dimensionElementRow.Name = "dimensionElementRow";
dimensionElementRow.Hierarchy = new HierarchyElement() { Name = "dimensionElementRow" };
foreach (PivotItem item in this.PGDatos.PivotRows)
{
string Nombre = item.FieldMappingName;

dimensionElementRow.Hierarchy.LevelElements.Add(new LevelElement() { Name = Nombre, DimensionName = item.FieldHeader });
}


SummaryElements summaries = new SummaryElements();


foreach (PivotComputationInfo item in this.PGDatos.PivotCalculations)
{
string Nombre = item.FieldName;

SummaryInfo Sumary = new SummaryInfo { Column = Nombre, Key = Nombre, Type = Syncfusion.Olap.Reports.SummaryType.Sum };

summaries.Add(Sumary);

meansureElements.Elements.Add(new MeasureElement() { Name = item.FieldName + "MM" });
}

olapReport.SeriesElements.Add(summaries);
olapReport.SeriesElements.Add(dimensionElementRow);
olapReport.CategoricalElements.Add(dimensionElementColumn);
olapReport.CategoricalElements.Add(meansureElements);

return olapReport;
}

But that doesn't work right. How should be the code of the function to work properly?

Thanks!

Ganesan
[Syncfusion]
Syncronize a OlapChart with a PivotGrid
June 9, 2011 08:43 AM
Hi Jorge,

You can achieve this adding the below code snippet .

private void Button_Click(object sender, RoutedEventArgs e)
{
OlapDataManager olapDataManager = new OlapDataManager();
olapDataManager.ItemSource = pivotGrid1.ItemSource; //ProductSales.GetSalesData();
olapDataManager.SetCurrentReport(CurrentReport());
this.olapchart1.OlapDataManager = olapDataManager;
this.olapchart1.OlapDataManager.CurrentReport.ShowExpanders = false;
this.olapchart1.Legend.RowsCount = 1;
this.olapchart1.Legend.ColumnsCount = 10;
this.olapchart1.Legend.Visibility = System.Windows.Visibility.Visible;
}

private OlapReport CurrentReport()
{
OlapReport olapReport = new OlapReport();

// Specifying the Row Dimension Element
DimensionElement dimensionElementRow = new DimensionElement();
dimensionElementRow.Name = "Geography";
dimensionElementRow.Hierarchy = new HierarchyElement() { Name = "Product Hierarchy" };
dimensionElementRow.Hierarchy.LevelElements.Add(new LevelElement() { Name = "Product" });
dimensionElementRow.Hierarchy.LevelElements.Add(new LevelElement() { Name = "Date" });

// Specifying the Column Dimension Element
DimensionElement dimensionElementColumn = new DimensionElement();
dimensionElementColumn.Name = "Geography";
dimensionElementColumn.Hierarchy = new HierarchyElement() { Name = "Geography Hierarchy" };
dimensionElementColumn.Hierarchy.LevelElements.Add(new LevelElement() { Name = "Country" });
dimensionElementColumn.Hierarchy.LevelElements.Add(new LevelElement() { Name = "State" });

//Specifying the Summary Elements
SummaryElements summaries = new SummaryElements();
summaries.Add(new SummaryInfo { Column = "Quantity", Key = "Quantity", Type = Syncfusion.Olap.Reports.SummaryType.Sum });
summaries.Add(new SummaryInfo { Column = "Amount", Key = "Amount", Type = Syncfusion.Olap.Reports.SummaryType.Sum, FormatString = "{0:c}" });

// Adding the Row Elements
olapReport.SeriesElements.Add(summaries);
olapReport.SeriesElements.Add(dimensionElementRow);
// Adding the Column Elements
olapReport.CategoricalElements.Add(dimensionElementColumn);
return olapReport;
}



We have also prepared a simple sample based on your requirement .Please download the sample from the below link

BindChartfrom PivotGrid19330643.zip


::adCenter::