Category / Section
How to display OLAP Chart and OLAP Grid on the same page in .NET WebForms ?
2 mins read
You can display OLAP Chart and OLAP Grid on the same page using the following code example at sample level.
HTML
<syncfusion:OlapGrid ID="OlapGrid1" runat="server"></syncfusion:OlapGrid> <syncfusion:OlapChart ID="OlapChart1" runat="server"></syncfusion:OlapChart>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Provide a valid connection string in the Data Source
DataManager = new OlapDataManager("Data Source=D:\\cube\\Adventure_Works_Ext.cub;Provider=MSOLAP");
DataManager.SetCurrentReport(CreateOlapReport());
this.OlapGrid1.OlapDataManager = DataManager;
this.OlapGrid1.EnableViewState = true;
this.OlapGrid1.DataBind();
this.OlapChart1.OlapDataManager = this.OlapGrid1.OlapDataManager;
this.OlapChart1.DataBind();
}
}
private OlapReport CreateOlapReport()
{
OlapReport olapReport = new OlapReport();
olapReport.CurrentCubeName = "Adventure Works";
DimensionElement dimensionElementColumn = new DimensionElement();
//Specifying the Name for the Dimension Element
dimensionElementColumn.Name = "Customer";
dimensionElementColumn.AddLevel("Customer Geography", "Country");
MeasureElements measureElementColumn = new MeasureElements();
//Specifying the Name for the Measure Element
measureElementColumn.Elements.Add(new MeasureElement { Name = "Internet Sales Amount" });
DimensionElement dimensionElementRow = new DimensionElement();
//Specifying the Dimension Name
dimensionElementRow.Name = "Date";
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year");
olapReport.SeriesElements.Add(dimensionElementRow);
olapReport.CategoricalElements.Add(dimensionElementColumn);
olapReport.CategoricalElements.Add(measureElementColumn);
return olapReport;
}
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If (Not IsPostBack) Then
'Provide a valid connection string in the Data Source
DataManager = New OlapDataManager("Data Source=D:\cube\Adventure_Works_Ext.cub;Provider=MSOLAP")
DataManager.SetCurrentReport(CreateOlapReport())
Me.OlapGrid1.OlapDataManager = DataManager
Me.OlapGrid1.EnableViewState = True
Me.OlapGrid1.DataBind()
Me.OlapChart1.OlapDataManager = Me.OlapGrid1.OlapDataManager
Me.OlapChart1.DataBind()
End If
End Sub
Private Function CreateOlapReport() As OlapReport
Dim olapReport As OlapReport = New OlapReport()
olapReport.CurrentCubeName = "Adventure Works"
Dim dimensionElementColumn As DimensionElement = New DimensionElement()
'Specifying the Name for the Dimension Element
dimensionElementColumn.Name = "Customer"
dimensionElementColumn.AddLevel("Customer Geography", "Country")
Dim measureElementColumn As MeasureElements = New MeasureElements()
measureElementColumn.Elements.Add(New MeasureElement With {.Name = "Internet Sales Amount"})
Dim dimensionElementRow As DimensionElement = New DimensionElement()
'Specifying the Dimension Name
dimensionElementRow.Name = "Date"
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year")
olapReport.SeriesElements.Add(dimensionElementRow)
olapReport.CategoricalElements.Add(dimensionElementColumn)
olapReport.CategoricalElements.Add(measureElementColumn)
Return olapReport
End Function