zoukankan      html  css  js  c++  java
  • java生成饼图

     pom.xml文件导入依赖包

    <!-- https://mvnrepository.com/artifact/org.jfree/jfreechart -->
    <dependency>
        <groupId>org.jfree</groupId>
        <artifactId>jfreechart</artifactId>
        <version>1.0.19</version>
    </dependency>
    package com.longteng.framework.asserts;
    
    import java.awt.Container;
    import java.awt.Font;
    
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.data.general.DefaultPieDataset;
    import org.jfree.data.general.PieDataset;
    import org.jfree.ui.ApplicationFrame;
    
    public class FirstJFreeChart extends ApplicationFrame {/** 
        * 
        */ 
        private static final long serialVersionUID = 1L;/** 
        * @param args 
        */ 
        public static void main(String[] args) {
            FirstJFreeChart chart = new FirstJFreeChart("每日水果组织结构图");
            chart.pack();
            chart.setVisible(true);
        }
        public FirstJFreeChart(String title) {
            super(title);
            setContentPane(createDemoPanel()); 
        }
        private Container createDemoPanel() {
            JFreeChart jFreeChart = createChart(createDataset());
            return new ChartPanel(jFreeChart); 
        }
        private PieDataset createDataset() {
            DefaultPieDataset dp = new DefaultPieDataset();    
            dp.setValue("苹果",100);
            dp.setValue("梨子",200);
            dp.setValue("葡萄",300);
            dp.setValue("香蕉",400);
            dp.setValue("荔枝",500);
            return dp; 
        }
        // 生成图标助对象JFreeChart 
        private JFreeChart createChart(PieDataset piedataset) {
            // 定义图标对象
            JFreeChart jFreeChart = ChartFactory.createPieChart("水果组织结构图", piedataset, true, true, false);
            //ChartFactory.createpi
            // 获得图表显示对象
            PiePlot piePlot = (PiePlot) jFreeChart.getPlot();
            // 设置图标标签字体
            piePlot.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
            piePlot.setNoDataMessage("No data available");
            piePlot.setCircular(true);// 间距
            piePlot.setLabelGap(0.01D);
            return jFreeChart; 
        } 
    } 

  • 相关阅读:
    C# this关键字的四种用法
    MVC Html.AntiForgeryToken() 防止CSRF攻击
    简单的C#网络爬虫
    string format的各类格式及用法
    选取两个有序数组中最大的K个值,降序存入另一个数组中
    程序员面试:青蛙跳台阶问题(变态跳台阶)
    贪心算法,递归算法,动态规划算法比较与总结
    storm简介[ZZ]
    逻辑回归:使用SGD(Stochastic Gradient Descent)进行大规模机器学习
    mahout分类
  • 原文地址:https://www.cnblogs.com/zhou-test/p/10058833.html
Copyright © 2011-2022 走看看