`
younglibin
  • 浏览: 1194006 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jfreeChart饼状图图参数设置

阅读更多
package com.iman.nrms.nrmwns.wrm.analyse.domain.util;

import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;

/**
 * 格式化 JFreeChart 输出图片使用
 * 
 *   
 * Author : 
 * Date   : Nov 26, 2009
 * Time   : 11:50:41 AM 
 * Version: 1.0
 */
public class FormatPic {
	/**
	 * 格式化饼状图使用
	 * 
	 * @param chart
	 * @returnType: void
	 * @author: 
	 * @data: Nov 26, 2009
	 * @time: 11:51:26 AM
	 */
	public static void setView(JFreeChart chart){
				  // 使下说明标签字体清晰,去锯齿类似于 
		   // chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);的效果 
		   chart.setTextAntiAlias(false); 
		   // 图片背景色 
		   chart.setBackgroundPaint(Color.white); 
		   // 设置图标题的字体重新设置title 
		   Font font = new Font("隶书", Font.BOLD, 25); 
		   TextTitle title = new TextTitle(chartTitle); 
		   title.setFont(font); 
		   chart.setTitle(title); 
		   PiePlot3D plot = (PiePlot3D) chart.getPlot(); 
		   // 图片中显示百分比:默认方式 
		   // 指定饼图轮廓线的颜色 
		   // plot.setBaseSectionOutlinePaint(Color.BLACK); 
		   // plot.setBaseSectionPaint(Color.BLACK); 
		   // 设置无数据时的信息 
		   plot.setNoDataMessage("无对应的数据,请重新查询。"); 
		   // 设置无数据时的信息显示颜色 
		   plot.setNoDataMessagePaint(Color.red); 
		   // 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位 
		   plot.setLabelGenerator(new StandardPieSectionLabelGenerator( 
			 "{0}={1}({2})", NumberFormat.getNumberInstance(), 
			 new DecimalFormat("0.00%"))); 
		   // 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例 
		   plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator( 
			 "{0}={1}({2})")); 
		   plot.setLabelFont(new Font("SansSerif", Font.TRUETYPE_FONT, 12)); 
		   // 指定图片的透明度(0.0-1.0) 
		   plot.setForegroundAlpha(0.65f); 
		   // 指定显示的饼图上圆形(false)还椭圆形(true) 
		   plot.setCircular(false, true); 
		   // 设置第一个 饼块section 的开始位置,默认是12点钟方向 
		   plot.setStartAngle(90); 
		   // // 设置分饼颜色 
		   plot.setSectionPaint(pieKeys[0], new Color(244, 194, 144)); 
		   plot.setSectionPaint(pieKeys[1], new Color(144, 233, 144)); 
		   FileOutputStream fos_jpg = null; 
		  
		   
		   // 高宽的设置影响椭圆饼图的形状 
		   ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 230); 
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics