How to: Bind a Web Chart to an ASPxPivotGrid

  • 3 minutes to read

This tutorial describes how to create a Web page with two linked controls: an ASPxPivotGrid bound to a data source, and a WebChartControl bound to that pivot grid.

Note that in order to synchronize both controls during callbacks, they should both be placed within an ASPxCallbackPanel, and have their EnableCallbacks properties disabled.

Tip

For the complete sample project, see the following DevExpress Support Center example: https://supportcenter.devexpress.com/ticket/details/e1242/how-to-link-a-web-chart-to-an-aspxpivotgrid.

This tutorial consists of the following sections.

Bind a Pivot Grid to Data

  1. Create a new ASP.NET Web Application (Visual Studio 2012, 2013, 2015, 2017, 2019 or 2022), or open an existing one.
  2. Drop the ASPxPivotGrid control from the DX.21.2: Data & Analytics toolbox tab onto the Web page.

    AddPivotGridToForm

  3. Bind the pivot grid to a database. To do this, click the pivot grid control’s smart tag. In the invoked Tasks list, expand the Choose Data Source drop-down menu and click New data source….

    SpecifyPivotGridDataSource

  4. Follow the steps in the Data Source Configuration Wizard, to connect to a data source. In this example, we’ll use the gsp.mdb file (which is shipped with the installation of the ASP.NET Chart Control), copied to the application’s folder.

    SelectGSPSource

  5. After you’ve connected to a data source, click the pivot grid’s smart tag again. In its Tasks list, choose Fields….

    SelectGridFields

  6. In the invoked dialog, click Retrieve fields.

    ClickRetrieveFields

  7. Remove the ID field, since it is unnecessary in this project.

    Remove_ID

  8. Specify the Area property for each field:

    • for the Region field, set this property to ColumnArea;
    • for the Year field, set this property to RowArea;
    • for the GSP field, set this property to DataArea.

    SpecifyGSPArea

    Click OK to close the dialog and apply the changes.

Now that the pivot grid is bound to data, the next step is to bind a Web chart to this grid.

Bind a Chart to the Pivot Grid

  1. Add a chart to the Web page.
  2. Click the chart control’s smart tag. In the invoked actions list, expand the Choose Data Source drop-down menu and select ASPxPivotGrid1.

    SetASP_PivotGrid

  3. Adjust chart options as required. For example, set the WebChartControl.ToolTipEnabled property to true to enable tooltips. You can also set the WebChartControl.CrosshairEnabled property to false to disable the crosshair cursor.

Get the Result

The WebChartControl is now bound to the ASPxPivotGrid. Run the application and view the result.

BindingToGridResult

Notice that once you filter the grid’s columns and rows in a browser, this has an immediate effect on the linked chart.

See Also