package com.cs.jfreechart; import java.awt.Color; import java.awt.Font; import java.io.FileOutputStream; import java.io.IOException; 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.PiePlot; import org.jfree.chart.title.LegendTitle; import org.jfree.chart.title.TextTitle; import org.jfree.data.general.DefaultPieDataset; public class PieChartDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { //生成饼图 JFreeChart chart = ChartFactory.createPieChart( "2014年收入预算", //图表标题 getDateSet(), //数据 true, //是否显示图例 false, //是否显示工具提示 false //是否生成URL ); //设置标题及标题字体 chart.setTitle(new TextTitle("2014年收入预算",new Font("黑体",Font.ITALIC,22))); // chart.setBackgroundPaint(Color.DARK_GRAY); //背景色 //建一个图例 LegendTitle legendTitle = chart.getLegend(0); //设置图例字体 legendTitle.setItemFont(new Font("宋体",Font.BOLD,12)); //获取饼图plot对象 PiePlot plot = (PiePlot) chart.getPlot(); //根据key指定各个数据饼图的颜色 // plot.setSectionPaint(Color.getColor("red")); // plot.setSectionPaint(Color.BLUE); // plot.setSectionPaint(Color.GREEN); // plot.setSectionPaint(Color.ORANGE); // plot.setSectionPaint(Color.CYAN); // plot.setSectionPaint(Color.DARK_GRAY); // plot.setSectionPaint(Color.GRAY); // plot.setSectionPaint(Color.getColor("#666")); // plot.setSectionPaint("南平闽延电力勘察设计有限公司", Color.getColor("#000")); //设置plot字体 //plot.setLabelFont(new Font("宋体",Font.BOLD,12)); plot.setLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 10)); plot.setPieIndex(1);//(Color.BLUE); // 设定背景透明度(0-1.0之间) plot.setBackgroundAlpha(0.1f); // plot.setBackgroundPaint(new Color(255,255,255)); //plot.setExplodePercent("南平闽延电力建设总公司", 0.1); //凸出模块 plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); //显示百分比 plot.setLabelBackgroundPaint(Color.WHITE); //提示背景颜色 plot.setForegroundAlpha(0.9f); //设定前景透明度(0-1.0之间) //设置背景透明度(0~1) //plot.setBackgroundAlpha(0.9f); //输出文件 FileOutputStream fos = new FileOutputStream("c:\\book2.jpg"); //用ChartUtilities工具输出 ChartUtilities.writeChartAsJPEG(fos, chart, 850, 500); fos.close(); } private static DefaultPieDataset getDateSet() { //提供生成饼图的数据 DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("南平闽延电力建设总公司", 300); dataset.setValue("福建省南平闽延电力建设有限公司", 250); dataset.setValue("福建省南平电气控制设备厂", 80); dataset.setValue("福建省南平闽延电力物资公司", 30); dataset.setValue("福建省南平闽延电力物业公司", 20); dataset.setValue("南平闽延科技开发中心", 50); dataset.setValue("南平闽延电力宾馆有限公司", 5); dataset.setValue("南平闽延汽车运输公司", 65); dataset.setValue("南平闽延电力勘察设计有限公司", 35); return dataset; } }

heshiyang LV1
2021年7月11日
kbl458 LV1
2020年8月20日
2410068425 LV23
2019年9月20日
cxy253030 LV6
2018年5月10日
Summer丶风华 LV2
2016年12月23日
caonimadaohao LV1
2016年12月22日
wing520 LV8
2016年5月6日
一抹纯白 LV4
2016年4月25日
a359355126 LV8
2016年4月22日
zhouwp LV10
2016年4月22日