当前位置:知识百问>百科问答>java使用jfreechart建立时序统计图

java使用jfreechart建立时序统计图

2024-12-23 14:13:32 编辑:join 浏览量:571

java使用jfreechart建立时序统计图

java使用jfreechart怎么建立时序统计图呢?我和大家分享一下怎么建立时序图,我写的经验对你学习java有帮助的话,给我投票、点赞或者收藏!

1java使用jfreechart制作3d条形图

1java使用jfreechart绘制线型统计图

2java使用jfreechart绘制条形统计图

eclipse新建一个java项目,名称为javachart。

在项目中增加freechart文件。

在项目中新建一个主类。

package javachart;

public class javachart {

public static void main(String[] args) {

// TODO Auto-generated method stub

}

}

在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);

}

在类中定义时序的数据,返回XYDataset类型的函数:

public static XYDataset shuju(){

TimeSeries ts=new TimeSeries("数据");

Day day = new Day(1, 1, 2018);

double d = 100D;

for (int i = 0; i < 365; i++) {

d = d + (Math.random() - 0.5) ;

ts.add(day, d);

day = (Day) day.next();

}

TimeSeriesCollection tc =new TimeSeriesCollection(ts);

return tc;

}

生成2018时序统计图:

public static JFreeChart tongjitu(){

StandardChartTheme standardChartTheme = new StandardChartTheme("CN");

standardChartTheme.setExtraLargeFont(new Font("宋书", Font.BOLD, 25));

standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));

standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));

ChartFactory.setChartTheme(standardChartTheme);

JFreeChart chart = ChartFactory.createTimeSeriesChart("2018产品销售统计图","月份","销售金额(万)", shuju(),false, false,false);

XYPlot plot = chart.getXYPlot();

plot.setDomainGridlinesVisible(true);

DateAxis da = (DateAxis) plot.getDomainAxis();

DateFormat format = new SimpleDateFormat("MM");

DateTickUnit dt = new DateTickUnit(DateTickUnit.DAY,30,format);

da.setTickUnit(dt);

return chart;

}

在窗口中显示统计图:

jf.add(new ChartPanel(tongjitu()));

运行项目,下图为销售时序统计图。

标签:java,jfreechart,统计图

版权声明:文章由 知识百问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.zhshbaiwen.com/answer/437127.html
热门文章