欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java,JFreeChat简单应用(二) 博客分类: Java JFreeChartJava 

程序员文章站 2024-03-20 12:12:34
...
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("XX公司组织结构图");
		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("guan li ren yuan", 10.02D);
		dp.setValue("shi chang ren yuan", 20.23D);
		dp.setValue("kai fa ren yuan", 60.02D);
		dp.setValue("OEM ren yuan", 10.02D);
		dp.setValue("qi ta ren yuan", 5.11D);
		return dp;
	}

	// 生成图标助对象JFreeChart
	private JFreeChart createChart(PieDataset piedataset) {
		// 定义图标对象
		JFreeChart jFreeChart = ChartFactory.createPieChart("XX公司组织结构tu",
				piedataset, true, true, false);
		// 获得图表显示对象
		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;
	}

}

 

 

Java,JFreeChat简单应用(二)
            
    
    博客分类: Java JFreeChartJava 

  • Java,JFreeChat简单应用(二)
            
    
    博客分类: Java JFreeChartJava 
  • 大小: 53.3 KB
相关标签: JFreeChart Java