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);
-
ClassDescriptionAbstractAxisData<Abscissa,
Ordinate> Represents the data for a line chart, a bar chart or a category bar chart.Represents common options for bar charts and category bar charts.AxisData<Abscissa,Ordinate> Represents the data for a line chart or a bar chart.
It contains multiple data points on a single axis.Provides bar chart options.A collection consists of multiple category slices.
It is represented on a category bar chart as bars of the same color.The data for category bar charts.The options for category bar charts.Abstract class used as the base for pie chart data as well as category bar chart data.
Represents multiple category slices.Represents a label and a numerical value.
It can be used either as a slice inside a pie chart, or as a bar in a category bar chart.Represents a chart.A factory class to create instances of different kinds of charts.Represents chart data.Represents the chart's display options.Represents the legend's position.Line<Abscissa,Ordinate> Represents a collections of points.
It is used inside an axis, as part of the line chart and bar chart data.The options for a line chart.Represents a chart's options.Represents the data for a pie chart.The class for pie chart options.Represents the common options for axis charts.
Notably line charts, bar charts and category bar charts.Represents the size of a two dimensional rectangle.The options for a line chart.Represents a template.