多语言展示
当前在线:392今日阅读:103今日分享:49

java使用jfreechart制作3d条形图

java使用jfreechart功能绘制3d条形图,我和大家分享一下jfreechart绘制统计图的方法,我写的经验对你学习java有帮助的话,给我投票、点赞或者收藏!1java使用jfreechar绘制饼型统计图2java使用jfreechart绘制条形统计图1java使用jfreechart绘制线型统计图
工具/原料

eclipse

方法/步骤
1

使用eclipse工具,新建一个java项目,项目的名称为javachart。

2

在项目添加jar:jfreechart.

3

在项目建立一个类:package javachart;public class javachart { 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 CategoryDataset shuju()     {        DefaultCategoryDataset dataset=new DefaultCategoryDataset();        dataset.setValue(10,'语文','100-120');        dataset.setValue(30,'语文','90-100');        dataset.setValue(10,'语文','80-90');        dataset.setValue(5,'语文','80以下');                dataset.setValue(20,'数学','100-120');        dataset.setValue(20,'数学','90-100');        dataset.setValue(5,'数学','80-90');        dataset.setValue(1,'数学','80以下');                dataset.setValue(30,'英语','100-120');        dataset.setValue(20,'英语','90-100');        dataset.setValue(2,'英语','80-90');        dataset.setValue(2,'英语','80以下');        return dataset;    }

6

定义一个3d条形统计图: public static JFreeChart tongjitu(CategoryDataset dataset)     { 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.createBarChart3D('各科成绩分布统计图', '成绩分布', '人数', dataset, PlotOrientation.VERTICAL, true, true, false);        chart.setBackgroundPaint(ChartColor.WHITE);        CategoryPlot p = chart.getCategoryPlot();        p.setBackgroundPaint(new ChartColor(245,245,245));        return chart;    }

8

统计图结果如下图。

推荐信息