How to: Visualize Pivot Grid Data in the XtraCharts Suite

  • 2 minutes to read

The following example shows how to bind a ChartControl to a PivotGridControl to visualize data.

In this example, after a Pivot Grid Control and ChartControl are created, the Pivot Grid Control instance is assigned to the ChartControl.DataSource property. By default, the ChartControl.AutoBindingSettingsEnabled property is set to true, so that binding settings are automatically adjusted, and no further customization is needed. Once the ChartControl is bound to the PivotGridControl, Pivot Grid Control data is immediately displayed in the chart.

The main form of this sample application 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).

using System;
using System.Windows.Forms;

namespace XtraPivotGrid_ChartsIntegration {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {

            // Populates the pivot grid's data source with data.
            this.salesPersonTableAdapter.Fill(this.nwindDataSet.SalesPerson);

            // Sets the PivotGridControl as a data source for the ChartControl.
            chartControl1.DataSource = pivotGridControl1;
        }
    }
}