http://www.javadrive.jp/jfreechart/
上記を参考にさせて頂きました。以下のサンプルコードは、チャートを表示した後に、画像ファイルを作成しています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jfree.chart.JFreeChart; | |
import org.jfree.chart.ChartFactory; | |
import org.jfree.data.category.DefaultCategoryDataset; | |
import org.jfree.chart.plot.PlotOrientation; | |
import javax.swing.JFrame; | |
import java.awt.BorderLayout; | |
import org.jfree.chart.ChartPanel; | |
import org.jfree.chart.ChartUtilities; | |
import java.io.File; | |
import java.io.IOException; | |
public class Test2_1 extends JFrame{ | |
public static void main(String[] args) { | |
Test2_1 frame = new Test2_1(); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setBounds(10, 10, 700, 700); | |
frame.setTitle("グラフサンプル"); | |
frame.setVisible(true); | |
} | |
Test2_1(){ | |
DefaultCategoryDataset data = new DefaultCategoryDataset(); | |
data.addValue(300, "America", "2005"); | |
data.addValue(500, "America", "2006"); | |
data.addValue(120, "America", "2007"); | |
JFreeChart chart = | |
ChartFactory.createLineChart("import", | |
"year", | |
"ton(t)", | |
data, | |
PlotOrientation.VERTICAL, | |
true, | |
false, | |
false); | |
ChartPanel cpanel = new ChartPanel(chart); | |
getContentPane().add(cpanel, BorderLayout.CENTER); | |
File file = new File("c:\\mdb\\filename.png"); | |
try { | |
ChartUtilities.saveChartAsPNG(file, chart, 300, 300); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
0 件のコメント:
コメントを投稿