Modifying a Chart Data Binding

The bindingInfo property of a Chart 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.

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

1. Add a new Chart element to the report.

For this example, do not open the 'Data Binding' dialog box. In the following steps, you will set the data source through the Chart's “query” property. In general, it does not matter how you initially con­figure the data binding, whether in script or through the 'Data Bind­ing' dialog box. In either case, you can use the bindingInfo properties in script to modify the data binding.

2. Right-click an empty area of the report, and select 'Script' from the context menu. This opens the Script Editor for editing the onLoad Handler of the report. Enter the commands below.

3. Bind the chart to the 'All Sales'

query: Graph1.query = "All Sales"; 

4. Specify query fields to bind to the X-axis ('Company') and Y-axis ('Total'):

 Graph1.bindingInfo.xFields = [["Company",Chart.STRING]];
 Graph1.bindingInfo.yFields = [["Total",Chart.NUMBER]]; 
dashboard demo
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Chart Data Binding

5. Set the aggregation/summarization method:

Graph1.bindingInfo.setFormula("Total",Chart.MAX_FORMULA) 

6. Set the desired grouping options (e.g., top-N filtering):

Graph1.bindingInfo.setTopN("Company",5)
Graph1.bindingInfo.setTopNReverse("Company",false)
Graph1.bindingInfo.setTopNSummaryCol("Company",
   "Max(Total)");

7. Specify the query fields to bind to a “VisualFrame,” (i.e., for visual coding as subseries):

Graph1.bindingInfo.setColorField("Employee",Chart.STRING); 

8. Close the Editor, an preview the report. The complete script is shown below:

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

Previous: Report Scripting - Creating Charts