How-To's > How do I create charts and graphs?
Use one of the six kinds of charts available in the javafx.scene.chart package to create a chart object:
| AreaChart | ![]() |
BarChart | ![]() |
| BubbleChart | ![]() |
LineChart | ![]() |
| PieChart | ![]() |
ScatterChart | ![]() |
A chart might contain one or several series of data. Use the corresponding classes to specify the data series for the particular type of chart.
The following code fragment constructs a simple pie chart by using the PieChart and PieChart.Data classes.
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.chart.*;
def pieChart = PieChart {
title: "Sample Pie"
data: [
PieChart.Data { label: "Apples" value: 34 }
PieChart.Data { label: "Oranges" value: 27 }
PieChart.Data { label: "Bananas" value: 16 }
PieChart.Data { label: "Grapes" value: 50 }
PieChart.Data { label: "Cherries" value: 6 }
PieChart.Data { label: "Raspberry" value: 7 }
]
}
Stage {
title: "Pie Chart"
scene: Scene{
width: 540
height: 410
content: pieChart
} //Scene
}//Stage
Tips
- The classes that reside in the
javafx.scene.chart.partpackage help you to set up the look and feel of the chart. - Use the
actioninstance variable of theDataclass to assign the specific behavior to the data item when it is clicked on. This variable adds interactivity to charts.
action:function(){ Alert.inform("Clicked on Austria=25601.34") }
Examples
- Shopping Mashup
This sample retrieves data from Delicious and Yahoo Shopping Web Services and builds a customized JavaFX mashup. - Building GUI Applications With JavaFX, Lesson 1: Quick JavaFX GUI Overview
- JavaFX Charts

Blog by Paul Bakker - Creating Charts in JavaFX

Blog by Dean Iverson - What's New in JavaFX 1.2: Charts

Article by Chris Wright and Jim Weaver
API Documentation
Last Updated: January 2010
[Return to How-To's Home]
Do you have comments about this article? We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.





