The following example shows how to bind a Chart control to a Pivot Grid to visualize data.
In this example, after an ASPxPivotGrid and WebChartControl are created, the pivot grid’s ID is assigned to the WebChartControl.DataSourceID property. By default, the WebChartControl.AutoBindingSettingsEnabled property is set to true
, so that binding settings are automatically adjusted, and no further customization is needed. Once the WebChartControl is bound to the ASPxPivotGrid, pivot grid data is immediately displayed in the Chart.
The sample web page contains the ‘Transpose Data Source’ check box that defines the pivot grid’s PivotGridOptionsChartDataSourceBase.ProvideDataByColumns property value. If the check box is checked, the property is set to false
, and series are created based on pivot grid rows (instead of columns, which is the default behavior).
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="ASPxPivotGrid_ChartIntegration._Default" %>
<%@ Register Assembly="DevExpress.XtraCharts.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.XtraCharts" TagPrefix="cc1" %>
<%@ Register Assembly="DevExpress.Web.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.XtraCharts.v14.2.Web, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.XtraCharts.Web" TagPrefix="dxchartsui" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxPivotGrid"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxe:ASPxCheckBox ID="ASPxCheckBox1" runat="server" Text="Transpose Data Source"
OnCheckedChanged="ASPxCheckBox1_CheckedChanged"
AutoPostBack="True">
</dxe:ASPxCheckBox>
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="AccessDataSource1"
OptionsView-ShowColumnGrandTotals="False" OptionsView-ShowRowGrandTotals="False">
<Fields>
<dx:PivotGridField ID="fieldShippedYear" Area="ColumnArea" AreaIndex="0"
Caption="Order Date" FieldName="OrderDate" GroupInterval="DateYear">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="0"
Caption="Quantity" FieldName="Quantity">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldSalesperson" Area="RowArea" AreaIndex="0"
Caption="Sales Person" FieldName="Sales_Person">
</dx:PivotGridField>
</Fields>
</dx:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/nwind.mdb"
SelectCommand="SELECT [OrderDate], [Quantity], [Sales Person] AS Sales_Person FROM [SalesPerson]">
</asp:AccessDataSource>
<dxchartsui:WebChartControl ID="WebChartControl1" runat="server" Width="700" Height="400">
</dxchartsui:WebChartControl>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
namespace ASPxPivotGrid_ChartIntegration {
public partial class _Default : Page {
protected override void OnInit(EventArgs e) {
base.OnInit(e);
// Specifies that Series data member values are created based on columns.
ASPxPivotGrid1.OptionsChartDataSource.ProvideDataByColumns = true;
// Specifies that data binding settings are automatically adjusted
// while retrieving data from the pivot grid.
WebChartControl1.PivotGridDataSourceOptions.AutoBindingSettingsEnabled = true;
// Sets the pivot grid as the chart's data source.
WebChartControl1.DataSourceID = "ASPxPivotGrid1";
}
protected void ASPxCheckBox1_CheckedChanged(object sender, EventArgs e) {
ASPxPivotGrid1.OptionsChartDataSource.ProvideDataByColumns = !ASPxCheckBox1.Checked;
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web.UI
Namespace ASPxPivotGrid_ChartIntegration
Partial Public Class _Default
Inherits Page
Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
' Specifies that Series data member values are created based on columns.
ASPxPivotGrid1.OptionsChartDataSource.ProvideDataByColumns = True
' Specifies that data binding settings are automatically adjusted
' while retrieving data from the pivot grid.
WebChartControl1.PivotGridDataSourceOptions.AutoBindingSettingsEnabled = True
' Sets the pivot grid as the chart's data source.
WebChartControl1.DataSourceID = "ASPxPivotGrid1"
End Sub
Protected Sub ASPxCheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
ASPxPivotGrid1.OptionsChartDataSource.ProvideDataByColumns = Not ASPxCheckBox1.Checked
End Sub
End Class
End Namespace
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="ASPxPivotGrid_ChartIntegration._Default" %>
<%@ Register Assembly="DevExpress.XtraCharts.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.XtraCharts" TagPrefix="cc1" %>
<%@ Register Assembly="DevExpress.Web.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.XtraCharts.v14.2.Web, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.XtraCharts.Web" TagPrefix="dxchartsui" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v14.2, Version=14.2.2.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxPivotGrid"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxe:ASPxCheckBox ID="ASPxCheckBox1" runat="server" Text="Transpose Data Source"
OnCheckedChanged="ASPxCheckBox1_CheckedChanged"
AutoPostBack="True">
</dxe:ASPxCheckBox>
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="AccessDataSource1"
OptionsView-ShowColumnGrandTotals="False" OptionsView-ShowRowGrandTotals="False">
<Fields>
<dx:PivotGridField ID="fieldShippedYear" Area="ColumnArea" AreaIndex="0"
Caption="Order Date" FieldName="OrderDate" GroupInterval="DateYear">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="0"
Caption="Quantity" FieldName="Quantity">
</dx:PivotGridField>
<dx:PivotGridField ID="fieldSalesperson" Area="RowArea" AreaIndex="0"
Caption="Sales Person" FieldName="Sales_Person">
</dx:PivotGridField>
</Fields>
</dx:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/nwind.mdb"
SelectCommand="SELECT [OrderDate], [Quantity], [Sales Person] AS Sales_Person FROM [SalesPerson]">
</asp:AccessDataSource>
<dxchartsui:WebChartControl ID="WebChartControl1" runat="server" Width="700" Height="400">
</dxchartsui:WebChartControl>
</div>
</form>
</body>
</html>