InetSoft Reporting Software: Report Scripting - Creating Charts .

Data Binding Summary

Data binding is the process of associating a set of data, usually a data model or the result set of a query, with a report element. Data binding is most commonly used with table, chart, and section elements, but can also be used with text-based elements. Elements can be bound to a data model, a query, or an asset. The data models and queries are created using the Data Modeler, and assets are created using the Data Worksheet.

Once a data model or a query is created using the Data Modeler, the data model or the query can be bound to a report element. If an element is bound, the element contents are retrieved from the database or any other data source at runtime. The following element types can have data bindings: Table, Section, Chart, Map, Text, and Textbox. It is important to note that unlike table or chart elements, a text element bound to data does not display any meta-data information in the Designer. The query result is only populated when the report is executed.

The ‘Data Binding’ tool is used to bind queries to elements in the Designer. Once the desired source of data has been selected, it is possible to refine the way it is bound to the element. For example, some columns may be hidden, conditions may be specified, and grouping and summarization may be added. There are five possible types of data sources to bind to elements: Query, Data Model, Report Data, Worksheet, and Parameter.

Charts display grouped and aggregated data in a graphical manner. The 'Properties' and 'Data Binding' dialog boxes for Charts provide many options for customization, including style, formatting, axis information, ranking, sorting, and so on. All of these various options are also accessible through script. See Modifying Chart Properties and Modifying a Chart Data Binding in this section for more information. The Chart API pro­vides access to the charting engine using Java object syntax. See Appendix CT:Chart Tutorial (API) for examples.

You can additionally modify charts in an extensive manner by using Chart API commands. For example, you can add graphical shapes or arbitrary text to the plot area, and you can annotate the chart based on the data that it displays. You can also build a chart from the ground-up completely within script. See Modifying a Chart Element using API Functions and Creating a Chart Using API Functions for examples of using the Chart API.

Modifying Chart Properties

To modify the basic properties of a Chart element, simply specify the desired property value in the onLoad Handler or Element Script. The following sections provide some basic examples of property modifications.

Whenever possible, use the Syntax Auto-Completion feature to enter legitimate property names and values.

Modifying the Chart Style

To modify the style of a chart in script (e.g., line, bar, pie, etc.), use the 'singleStyle' or 'separatedStyle' attributes:

You can switch between 'Single Graph' and 'Separate Graph' in the 'Data Binding' dialog box. See Chart Data Binding in the Report Designer for more information.

• Use 'singleStyle' when the chart is in 'Single Graph' mode. In 'Single Graph' mode, you can assign a different style to each individual dataset.

• Use 'separatedStyle' when the chart is in 'Separate Graph' mode. In 'Separate Graph' mode, you can assign a single style to all datasets.

For example, if you want to parameterize the style of a chart ('Separate Graph'), you could prompt the user for a parameter called 'Chart Style'. Then access this parameter in the chart script and modify the chart style accordingly.

if (parameter['Chart Style'] == 'bar') {
   Graph1.separatedStyle=Chart.CHART_BAR;
}
else if (parameter['Chart Style'] == 'line') {
   Graph1.separatedStyle=Chart.CHART_LINE;
}

Modifying Axis Title Text

To modify axis title text, use xTitle.text (x2Title.text) and yTitle.text, (y2Title.text).

Graph1['xTitle.text'] = 'Text to go below bottom X-axis'
Graph1['x2Title.text'] = 'Text to go above top X-axis'

Modifying Axis Properties

To modify axis properties, including labels, visibility, tick marks, etc., use the “axis” properties (axis.font, axis.minimum, axis.labelColor, etc.). Use auto-complete for correct syntax. Type “.” after “axis” to see prompt.

Graph1.axis.Employee.font='Comic Sans MS-BOLD-12'
Graph1.axis.Employee.ticksVisible=false
Graph1.axis.Employee.labelColor=[0,0,255]
Graph1.axis['Sum(Total)'].logarithmic=true
Graph1.axis['Sum(Total)'].minimum=10000

To modify the format of a label, define a new format object, and assign it to the axis.format property.

var fmt = new inetsoft.uql.XFormatInfo;
fmt.setFormat(Chart.DECIMAL_FORMAT);
fmt.setFormatSpec("#,###.00")
Graph1.axis['Sum(Total)'].format = fmt;
Previous: Charting Control - Visual Properties