Java Reference
In-Depth Information
Visualizing data with the JavaFX chart API
Up to this point, all of the recipes in this chapter dealt with retrieving, processing, or storing
data. What about visualizing the data? As with other rich client platforms, JavaFX provides a
wealth of data visualization tools in the form of the Chart-API. This recipe shows you how to
use the Chart API to create a visual rendition of your data in the form of charts.
Getting ready
This recipe involves discussion about JavaFX's Chart API located in package javafx.scene.
chart . As of version 1.2 of the platform, the API offers support for more than half a dozen
charts. All charts, however, share a common implementation design, which makes the creation
of all charts a similar exercise. The example presented for this recipe will show you how to create
a bar chart. However, the steps necessary to create other types of charts are similar.
How to do it...
The next code snippet shows you how to create a bar chart in JavaFX. As you will see, it is
simple and straightforward. Refer to ch06/source-code/src/chart/BarChartDemo.fx
for the full listing.
var categories = ["Q32009", "Q32008"];
var dataSeries = [
BarChart.Series {
name: "Nokia"
data: [
BarChart.Data {category: categories[0] value: 16.1},
BarChart.Data {category: categories[1] value: 15.4}
]
},
BarChart.Series {
name: "RIM"
data: [
BarChart.Data {category: categories[0] value: 8.5},
BarChart.Data {category: categories[1] value: 5.8}
]
},
BarChart.Series {
name: "Apple"
data: [
BarChart.Data {category: categories[0] value: 7},
 
Search WWH ::




Custom Search