java利用jfreechart功能绘制线型统计图,我和大师分享一下jfreechart绘制统计图的方式,我写的经验对你进修java有帮忙的话,给我投票、点赞或者保藏!

工具/原料
- eclipse
方式/步骤
- 1
利用eclipse新建一个java项目,项目名称javachar。

- 2
在项目增添jfreechart文件,没有这个文件时上百度下载。

- 3
在项目中新建一个本家儿类:
package javachar;
public class javachar {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}

- 4
在main方式中,建立一个窗口显示统计图。
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame jf=new JFrame();
jf.setSize(600,500);
jf.setLocationRelativeTo(null);
jf.setVisible(true);
}

- 5
在类中界说函数,返回要统计的数据:
public static DefaultCategoryDataset shuju(){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue( 100 ,"2018" ,"1" );
dataset.addValue( 60 ,"2018" ,"2" );
dataset.addValue( 150 ,"2018" ,"3" );
dataset.addValue( 170 ,"2018" ,"4" );
dataset.addValue( 180 ,"2018" ,"5" );
dataset.addValue( 200 ,"2018" ,"6" );
dataset.addValue( 130 ,"2018" ,"7" );
dataset.addValue( 190 ,"2018" ,"8" );
dataset.addValue( 120 ,"2018" ,"9" );
dataset.addValue( 130 ,"2018" ,"10" );
dataset.addValue( 170 ,"2018" ,"11" );
dataset.addValue( 50 ,"2018" ,"12" );
return dataset;
}

- 6
生当作统计图:
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
standardChartTheme.setExtraLargeFont(new Font("宋书", Font.BOLD, 26));
standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 16));
standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 16));
ChartFactory.setChartTheme(standardChartTheme);
JFreeChart chart = ChartFactory.createLineChart(
"年发卖金额分布图","月份",
"发卖金额(万)",
dataset,PlotOrientation.VERTICAL,
true,true,false);
return chart;

- 7
在窗口中显示统计图:
jf.add(new ChartPanel(tongjitu(shuju())));

- 8
运行项目,统计图如下图。









