用jFreeChart制作一个饼状的图形统计图
2014-09-12 19:16
141 查看
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) {} } } }
效果图如下:
相关文章推荐
- Java程序中用JFreeChart制作图形报表
- 一个统计用的饼状图的函数
- 使用JFreeChart制作图形报表
- C#+JQuery+.Ashx+百度Echarts实现全国省市地图和饼状图动态数据图形报表的统计
- ECharts的学习(二):制作一个简单的饼状图,并对其设置样式
- 一个能对访问者进行编号、记录访问次数、IP、时间的统计制作实例
- 使用JFreeChart制作图形
- Asp.net中制作柱状饼状报表统计图
- JFreeChart各种图形的制作
- 使用D3制作统计图表、线性图表、水平柱状图表、饼图 -- (五)饼状图表
- 在《Android PorterDuff.Mode图形混合处理 》这篇博客中,我们讲解了PorterDuff.Mode对图形混合的处理。这篇我们将通过图形混合的原理,来制作一个手动擦除蒙版显示底层图片
- 一个ASP统计制作实例
- JFreechart 制作柱状图、饼图、折线图、仪表图等统计图的使用方法
- Python制作统计图形
- Java程序中用JFreeChart制作图形报表-Java基础-Java-编程开发
- Java面向对象深入学习:制作一个画图工具并计算那些图形的面积和周长。
- 使用JFreeChart制作图形报表
- 使用JFreeChart制作图形报表
- 项目:(前端部分)制作一个导航目录表格,统计黄石港区各社区各类人数
- C#+JQuery+.Ashx+百度Echarts 实现全国省市地图和饼状图动态数据图形报表的统计