java使用jfreechar绘制饼型统计图

释放双眼,带上耳机,听听看~!

在java应用程序中怎么绘制统计图呢,我和大家分享一下jfreechart绘制统计图的方法,我写的经验对你学习java有帮助的话,给我投票、点赞或者收藏!

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

java使用jfreechar绘制饼型统计图


工具/原料

  • eclipse

方法/步骤

  1. 1

    使用eclipse,新建一个java项目,项目的名称javachar。

    java使用jfreechar绘制饼型统计图

  2. 2

    在项目中增加jfreechar类库,没有jfreechar下载,http://www.jfree.org/jfreechart/download/。

    java使用jfreechar绘制饼型统计图

  3. 3

    新建一个javachar.java类,带有main方法的主类。

    public class javachar {

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    }

    }

    java使用jfreechar绘制饼型统计图

  4. 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);

    }

    java使用jfreechar绘制饼型统计图

  5. 5

    在类中定义统计图的数据。

    public static PieDataset shuju( ) 

    {

         DefaultPieDataset dataset = new DefaultPieDataset( );

         dataset.setValue( \"安阳一中\" , new Double( 50 ) );  

         dataset.setValue( \"安阳二中\" , new Double( 100 ) );   

         dataset.setValue( \"安阳三中\" , new Double( 150 ) );    

         dataset.setValue( \"安阳六中\" , new Double( 80 ) );  

         return dataset;         

    }

    java使用jfreechar绘制饼型统计图

  6. 6

    定义饼型图:

    public static JFreeChart createChart( PieDataset dataset )

    {

    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.createPieChart(\"中学招生人数\",dataset, true, true,  false);

       return chart;

    }

    java使用jfreechar绘制饼型统计图

  7. 7

    在main方法中,把统计图增加到窗口中。

    jf.add(new ChartPanel(createChart(shuju())));

    java使用jfreechar绘制饼型统计图

  8. 8

    运行项目,结果如下图。

    java使用jfreechar绘制饼型统计图

给TA打赏
共{{data.count}}人
人已打赏
经验

在英文Server 2003中怎么设置相同的程序分组?

2020-11-9 3:35:16

经验

excel弹出数据验证限制不匹配,无法输入怎么办

2020-11-9 3:35:50

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索