使用JFreeChart生成饼图,不做任何注释,只求应用,生成的饼图放在D:\\fruit.jpg

/**
 * 要是用JFreeChar生成饼图,不做任何注释,只求应用,生成的饼图放在D:\\fruit.jpg
 * 
 * 1.加入jcommon-1.0.5.jar和jfreechart-1.0.2.jar
 * 
 * 2.设置值
 * dataset.setValue("苹果", 100);
 * dataset.setValue("梨子", 200);
 * dataset.setValue("葡萄", 300);
 * dataset.setValue("香蕉", 400);
 * dataset.setValue("荔枝", 500);
 * 
 * fos_jpg = new FileOutputStream("D:\\fruit.jpg");
 */
package com.bjpowernode.drp.statreport;

import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;

public class PieCharDemo {

	public static void main(String[] args) throws IOException {
		
		DefaultPieDataset data = getDataSet();
		
		JFreeChart chart = ChartFactory.createPieChart3D("水果产量图",
				data,
				true,
				false,
				false);
		
		FileOutputStream fos_jpg = null;
		
		try {
			fos_jpg = new FileOutputStream("D:\\fruit.jpg");
			
			PiePlot3D plot = (PiePlot3D) chart.getPlot();
			
			plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
					"{0}={1}({2})", NumberFormat.getNumberInstance(),
					new DecimalFormat("0.00%")));
			plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
					"{0}={1}({2})"));
			
			ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 400, 300,null);
			
		} finally {
			try {
				fos_jpg.close();
				
			} catch (Exception e) {
				throw new RuntimeException("生成饼图失败!");
			}
		}

	}

	
	private static DefaultPieDataset getDataSet() {
		
		DefaultPieDataset dataset = new DefaultPieDataset();
		
		dataset.setValue("苹果", 100);
		dataset.setValue("梨子", 200);
		dataset.setValue("葡萄", 300);
		dataset.setValue("香蕉", 400);
		dataset.setValue("荔枝", 500);
		
		return dataset;
	}

}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值