Package com.orchestranetworks.addon.dqid.chart


package com.orchestranetworks.addon.dqid.chart

Provides classes to define charts and write them to an HTML document.

The chart API allows the creation of a multitude of chart types using custom data and options. The supported charts are: Line charts, bar charts, pie charts and category bar charts.

Note: The provided API is a beta version. Data structures and options classes are subject to change.

Example of usage

Below is an example of usage of the API. In this example a pie chart is created as part of a UI service.

Preparing the framework

Before writing any charts to the HTML page it is necessary to prepare the Chart API. Preparing the Chart API ensures that all the required javascript libraries are included and the necessary javascript code is generated.

Next a pie chart will be created. Any chart type is composed of the data, the options and the display options

The data

A pie chart is composed of slices that associate a label with a numerical value. In this example the pie chart will be composed of 3 slices.

        PieChartData pieChartData = new PieChartData();
        UserMessage labelA = UserMessage.createInfo("A");
        CategorySlice sliceA = new CategorySlice(labelA, 1.66);
        UserMessage labelB = UserMessage.createInfo("B");
        CategorySlice sliceB = new CategorySlice(labelB, 5);
        UserMessage labelC = UserMessage.createInfo("C");
        CategorySlice sliceC = new CategorySlice(labelC, 3.333);
        pieChartData.addCategorySlice(sliceA);
        pieChartData.addCategorySlice(sliceB);
        pieChartData.addCategorySlice(sliceC);

The options

Next the options object is created. For this particular example the options will hide the legend and annotate each slice with the corresponding label and value.

        PieChartOptions pieChartOptions = new PieChartOptions();
        pieChartOptions.showLegend(false);
        pieChartOptions.showLabels(true);

Consult the documentation for details regarding all available options.

The display options

The display options determine the size of a chart as well as the size of the legend. A custom CSS class can also be set for the chart container to further customize its look. Consult the documentation for more details. In this example the display options are used to set the chart's width to 400 and its height to 300.

        DisplayOptions displayOptions = new DisplayOptions();
        displayOptions.setSize(new Size(400,300));

Creating the chart and writing it to the HTML document.

The ChartFactory is used to create chart instances.

After the chart is created it must be written to the HTML document

        Chart pieChart = ChartFactory.newPieChart(pieChartData, pieChartOptions, displayOptions);
        pieChart.prepareResources(writer);
        pieChart.write(writer);