admin 管理员组

文章数量: 887006

java 画饼状图

jar包:

效果:

代码:

import java.awt.Color;
import java.io.File;import org.jfree.chart.ChartColor;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RefineryUtilities;public class ChartPie1 {public static void main(String[] args) {DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("A", new Double(20));dataset.setValue("B", new Double(20));dataset.setValue("C", new Double(40));dataset.setValue("D", new Double(10));dataset.setValue("E", new Double(10));dataset.setValue("F", new Double(10));dataset.setValue("G", new Double(10));dataset.setValue("H", new Double(10));dataset.setValue("I", new Double(10));dataset.setValue("J", new Double(10));dataset.setValue("K", new Double(10));JFreeChart chart = ChartFactory.createPieChart("Mobile Sales", // chartdataset, // datatrue, // include legendtrue, false);setChart(chart);PiePlot pieplot = (PiePlot) chart.getPlot();    pieplot.setSectionPaint("A", Color.decode("#749f83"));    pieplot.setSectionPaint("B", Color.decode("#2f4554"));    pieplot.setSectionPaint("C", Color.decode("#61a0a8"));    pieplot.setSectionPaint("D", Color.decode("#d48265"));    pieplot.setSectionPaint("E", Color.decode("#91c7ae"));    pieplot.setSectionPaint("F", Color.decode("#c23531"));    pieplot.setSectionPaint("G", Color.decode("#ca8622"));    pieplot.setSectionPaint("H", Color.decode("#bda29a"));    pieplot.setSectionPaint("I", Color.decode("#6e7074"));    pieplot.setSectionPaint("J", Color.decode("#546570"));    pieplot.setSectionPaint("K", Color.decode("#c4ccd3"));    try {
//			// 创建图形显示面板
//			ChartFrame cf = new ChartFrame("柱状图", chart);
//			// cf.pack();
//			// // 设置图片大小
//			cf.setSize(width, height);
//			// // 设置图形可见
//			cf.setVisible(true);
// 保存图片到指定文件夹ChartUtilities.saveChartAsPNG(new File("d:\\PieChart2.png"), chart, 1500, 800);System.err.println("成功");} catch (Exception e) {System.err.println("创建图形时出错");}}public static void setChart(JFreeChart chart) {chart.setTextAntiAlias(true);PiePlot pieplot = (PiePlot) chart.getPlot();// 设置图表背景颜色pieplot.setBackgroundPaint(ChartColor.WHITE);pieplot.setLabelBackgroundPaint(null);// 标签背景颜色pieplot.setLabelOutlinePaint(null);// 标签边框颜色pieplot.setLabelShadowPaint(null);// 标签阴影颜色pieplot.setOutlinePaint(null); // 设置绘图面板外边的填充颜色pieplot.setShadowPaint(null); // 设置绘图面板阴影的填充颜色pieplot.setSectionOutlinesVisible(false);        pieplot.setNoDataMessage("没有可供使用的数据!");        }
}


本文标签: java 画饼状图