2010年2月16日火曜日

groovyとJFreeChartで箱ひげグラフを描画する

groovyとJFreeChartで箱ひげグラフを描画するには、以下のコードを実行します。

import org.jfree.chart.*
import org.jfree.chart.plot.*
import org.jfree.data.statistics.*

ds = new DefaultBoxAndWhiskerCategoryDataset()
ds.with {
d1 = [90, 93, 88, 89, 92, 97, 94, 93, 93, 87, 90, 95]
add(d1, "製品1", "Jan 2010")
d2 = [96, 91, 97, 91, 90, 94, 99, 98, 96, 87, 96, 96]
add(d2, "製品1", "Feb 2010")
}

jfc = ChartFactory.createBoxAndWhiskerChart(
"歩留まり率推移",
"年月",
"歩留まり率",
ds,
true)


ChartUtilities.saveChartAsPNG(
new File("./baw-chart.png"), jfc, 300, 200)


出力画像(baw-chart.png)


動作環境
JDK1.6 Update 15, groovy 1.6.3, JFreeChart1.0.13, JCommon1.0.16

0 件のコメント:

コメントを投稿