Java Reference
In-Depth Information
How it works...
As mentioned earlier, creating a chart is easy and straight forward. In this example, we use
data from a Gartner report (see http://www.gartner.com/it/page.jsp?id=1224645 )
to display smartphone sales for Q309 versus Q308. The code to produce the chart from
the tabular data provided in the report is deceptively simple. Let's see how the chart
was produced:
F Categories—first, the code declares the data categories for the chart. A category
is a broad, logical grouping of related data points. In the code snippet, variable
categories is declared as a sequence of strings representation two categories
"Q32009" and "Q32008".
F Data series—next, variable dataSeries is assigned a sequence of BarChart.
Series instances. The Series class encapsulates the definition of one or more
data points on the chart. Each Series instance has a name and contains a
sequence of data points bound to a category (see previous bullet). The Chart API
uses that information to generate each bar in the chart, select a color for the bar,
and automatically generate the legend for the chart.
The last step is to place the generated chart on the stage. The chart automatically sizes itself
to display the data properly. However, you can use the myriad of properties exposed by the
Chart API to customize the look of your charts.
There's more...
Charts from the Chart API can be grouped in two major categories: XYChart, which represents
charts with two-axis charts and PieChart (and its 3D version PieChart3D). As of version 1.2,
XYChart classes can be further grouped as follows:
F BarChart and BarChart3D
F LineChart and AreaChart
F BubbleChart and ScatterChart
Each chart type listed shares similar properties, which makes it easy to switch between them.
For instance, going from BarChart to BarBarChart3D involves a simple class substitution,
which produces a 3D version of the chart, as shown in the following screenshot:
 
Search WWH ::




Custom Search