package jfreechart;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

/**
* 円グラフのサンプル
*/
public class PieChartSample {
public static void main(String[] args) {
// (1)データセットの作成
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Category 1", 50);
data.setValue("Category 2", 40);
data.setValue("Category 3", 30);
data.setValue("Category 4", 20);
data.setValue("Category 5", 10);
data.setValue("Category 6", 5);

// (2)JFreeChartオブジェクトの生成
JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart",
data, true, true, false);

// (3)グラフの出力
File outputFile = new File("./output/SamplePieChart.png");
try {
ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 500);
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
}
}