用jFreeChart制作一个饼状的图形统计图
来源:互联网 发布:dsp竞价算法 编辑:程序博客网 时间:2024/05/01 21:26
package com.test.chart;import java.awt.Color;import java.awt.Font;import java.io.FileOutputStream;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;import org.jfree.util.Rotation;public class PieChartDemo {private static DefaultPieDataset getDataSet() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("剩余容量",0.5); dataset.setValue("已用容量",1.5); return dataset; } public static void main(String[] args) throws Exception { Font font = new Font("Microsoft YaHei",Font.BOLD,12); DefaultPieDataset data = getDataSet(); JFreeChart chart = ChartFactory.createPieChart3D(null, data, false, false, false ); //获得3D的水晶饼图对象 PiePlot3D pieplot3d = (PiePlot3D) chart.getPlot(); //获取图像的对象,设置字体。不设置字体中文乱码 pieplot3d.setLabelFont(font); //设置开始角度 pieplot3d.setStartAngle(70D); //设置方向为”顺时针方向“ pieplot3d.setDirection(Rotation.CLOCKWISE); //设置透明度,0.5F为半透明,1为不透明,0为全透明 pieplot3d.setForegroundAlpha(0.6F); pieplot3d.setNoDataMessage("无数据显示"); //给标签的显示加上百分比格式 StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator(("{0}{2}"), NumberFormat.getNumberInstance(),new DecimalFormat("0.00%")); pieplot3d.setLabelGenerator(generator); //标签与图形之间的距离 //pieplot3d.setLabelLinkMargin(-0.05); //设置连线的颜色 //pieplot3d.setLabelLinkPaint(new Color(0, 180, 205)); pieplot3d.setSimpleLabels(true); //为分区设置指定的颜色 pieplot3d.setSectionPaint("剩余容量", new Color(125, 125, 125)); pieplot3d.setSectionPaint("已用容量", new Color(0, 180, 205)); //设置绘图面板外边以及阴影的填充颜色 pieplot3d.setOutlinePaint(Color.RED); pieplot3d.setShadowPaint(Color.BLUE); //设置整个面板的背景色 pieplot3d.setBackgroundPaint(new Color(238, 241, 242)); //pieplot3d.setBackgroundPaint(null); //设置标签背景颜色、边框颜色、阴影颜色和文字颜色 pieplot3d.setLabelBackgroundPaint(null); pieplot3d.setLabelOutlinePaint(null); pieplot3d.setLabelShadowPaint(null); pieplot3d.setLabelPaint(new Color(120, 120, 120)); //重新设置图例的字体,保证汉字显示 //LegendTitle legend = chart.getLegend(); //legend.setItemFont(font); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream("D:\\fruit.jpg"); ChartUtilities.writeChartAsJPEG(fos_jpg, chart, 490, 300, null); } finally { try { fos_jpg.close(); } catch(Exception e) {} }}}
效果图如下:
0 0
- 用jFreeChart制作一个饼状的图形统计图
- JFreeChart各种图形的制作
- 使用JFreeChart制作图形
- 使用JFreeChart制作图形报表
- 使用JFreeChart制作图形报表
- 使用JFreeChart制作图形报表
- JFreechart 制作柱状图、饼图、折线图、仪表图等统计图的使用方法
- JFreeChart统计图
- 统计图JFreeChart
- 统计图JFreeChart
- JFreeChart统计图
- 制作统计图好用的软件
- jfreechart创建包含Map对象的统计图
- Java程序中用JFreeChart制作图形报表
- 制作带有超级连接的统计图
- 图形统计图
- 使用JFreeChart构造统计图
- jfreechart生成不同统计图
- Android中的颜色设置
- Java web开发Extjs与Spring入门实例
- 如何修改Mac截屏保存路径
- MakeKeyLparam 的简化
- linux鸟哥的私房菜读书笔记【管线命令(pipe)】
- 用jFreeChart制作一个饼状的图形统计图
- UVA - 10129 Play on Words
- 动态规划之最长公共子序列
- 【产品经理】总结产品经理职责和素质
- 如何在win7 中安装windows sdk 7.1
- spring cron表达式
- Oracle外连接中对非连接条件使用(+)的作用
- J2EE的四层结构简介
- UVA10602