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

    1、生成饼图的代码如下:

    /**
     * @Title:PieChart.java
     * @Package:com.you.jfreechart
     * @Description:生成饼图
     * @author:Youhaidong(游海东)
     * @date:2013-7-22 下午11:41:11
     * @version V1.0
     */
    package com.you.jfreechart;
    
    import java.awt.Font;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartFrame;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.chart.title.LegendTitle;
    import org.jfree.data.general.DefaultPieDataset;
    
    /**
     * 类功能说明
     * 类修改者 修改日期
     * 修改说明
     * <p>Title:PieChart.java</p>
     * <p>Description:游海东个人开发</p>
     * <p>Copyright:Copyright(c)2013</p>
     * @author:游海东
     * @date:2013-7-22 下午11:41:11
     * @version V1.0
     */
    public class PieChart {
    
    	/**
    	 * @Title:main
    	 * @Description:饼图类
    	 * @param:@param args
    	 * @return: void
    	 * @throws
    	 */
    	public static void main(String[] args) {
    		//
    		DefaultPieDataset dpd = new DefaultPieDataset();
    		//设置值
    		dpd.setValue("苹果", 145);
    		dpd.setValue("梨子", 245);
    		dpd.setValue("香蕉", 345);
    		dpd.setValue("菠萝", 645);
    		dpd.setValue("桃子", 945);
    		dpd.setValue("柚子", 445);
    		dpd.setValue("橘子", 745);
    		dpd.setValue("李子", 845);
    		dpd.setValue("荔枝", 545);
    		dpd.setValue("蛇果", 1045);
    		
    		//生成饼图
    		JFreeChart chart = ChartFactory.createPieChart("水果数量分布", dpd, true, true, false);
    		//解决标题乱码
    		chart.getTitle().setFont(new Font("宋体",Font.BOLD,20));
    		
    		ChartFrame chartFrame = new ChartFrame("水果数量分布", chart);
    		chartFrame.pack();
    		chartFrame.setVisible(true);
    		
    		//解决饼图的乱码
    		PiePlot plot = (PiePlot)chart.getPlot();
    		plot.setLabelFont(new Font("宋体",Font.BOLD,12));
    		
    		//解决Legend乱码问题
    		LegendTitle legendTitle = chart.getLegend(0);
    		legendTitle.setItemFont(new Font("宋体",Font.BOLD,12));
    		
    	}
    
    }
    

    2、结果如下图:


  • 相关阅读:
    java.lang.NoClassDefFoundError: sun/swing/plaf/synth/SynthIcon
    微信数据库解密--代码报错:未定义标识符 HMAC_CTX_init
    Windows家庭版组策略编辑
    Visual Studio x64 使用 .asm 文件
    某数据库管理软件离线注册分析
    EV剪辑分析
    ciscn_lonelywolf
    arm-pwn
    libc-2.32.so在orw上与其他版本的区别
    更新libc
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315764.html
Copyright © 2011-2022 走看看