3.1. Simple pie chart
Pie charts must use Defaultpiedataset to provide data for the chart.
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Spring Security", 100);
dataset.setValue("jBPM 4", 200);
dataset.setValue("Ext JS", 300);
dataset.setValue("JFreeChart", 100);
This time we use SetValue to add data to the dataset, the first parameter is the name of the data, and the second data is the value of the data.
This exposes a problem with Jfreechart, and cannot use the unified DataSet interface to set the data.
The next step is to create a pie chart by using the Charfactory Createpiechart method.
JFreeChart chart = ChartFactory.createPieChart(
"chart", // 标题
dataset, // 数据
true, // 是否使用legend
false, // 是否使用tooltip
false // 是否使用url链接
);
Finally, use Charutilities to export Jfreechart as a picture.
Figure 3.1. Simple pie chart