Modify Chart Data Binding

The Chart bindingInfo property provides access to the data binding options in the Chart’s ‘Data Binding’ dialog box. This includes the binding of fields to the X-axis, Y-axis, and VisualFrames (Color, Shape, etc.), as well as grouping and summarization settings.

Walkthrough

In the following example, you will bind a chart to the ‘All Sales’ Data Worksheet, set the axis bindings, define a subseries, and set grouping and summarization. Follow the steps below:

  1. Create a Dashboard. Select the ‘All Sales’ Data Worksheet as the data source. (See Create a New Dashboard.)

    The ‘All Sales’ Data Worksheet can be found in the Data Worksheet  Sample Queries folder. You may need to download the examples.zip file from GitHub into your environment. (This requires access to Enterprise Manager.) See Import and Export Assets for instructions on how to import.
  2. Add a new Chart component to the Dashboard. (The default name of this Chart is “Chart1”.)

  3. Press the ‘Options’ button setting in the toolbar to open the ‘Dashboard Options’ dialog box, then select the Script tab to open the onRefresh Handler.

    Changest to the bindingInfo property must in general be made prior to query execution. Therefore, attach bindingInfo scripts to the onRefresh handler.
  4. In onRefresh Handler in the Script Editor, enter the commands below:

    1. Bind the chart to the ‘All Sales’ data block.

      Chart1.query = "All Sales";
    2. Specify query fields to bind to the X-axis (‘Company’) and Y-axis (‘Total’):

      Chart1.bindingInfo.xFields = [["Company",Chart.STRING]];
      Chart1.bindingInfo.yFields = [["Total",Chart.NUMBER]];
    3. Set the aggregation/summarization method:

      Chart1.bindingInfo.setFormula("Total",Chart.MAX_FORMULA)
    4. Set the desired grouping options (e.g., top-N filtering):

      Chart1.bindingInfo.setTopN("Company",5)
      Chart1.bindingInfo.setTopNReverse("Company",false)
      Chart1.bindingInfo.setTopNSummaryCol("Company","Max(Total)");
    5. Specify the query fields to bind to a ColorFrame (i.e., for color-coding as subseries):

      Chart1.bindingInfo.setColorField("Employee",Chart.STRING);
  5. Close the Editor and press the ‘Preview’ button preview to preview the Dashboard.

    ModifyingChartBinding

Complete Script
Chart1.query = "All Sales";
Chart1.bindingInfo.xFields = [["Company",Chart.STRING]];
Chart1.bindingInfo.yFields = [["Total",Chart.NUMBER]];
Chart1.bindingInfo.setFormula("Total",Chart.MAX_FORMULA)
Chart1.bindingInfo.setTopN("Company",5)
Chart1.bindingInfo.setTopNReverse("Company",false)
Chart1.bindingInfo.setTopNSummaryCol("Company","Max(Total)");
Chart1.bindingInfo.setColorField("Employee",Chart.STRING);