JFreechart环形图

生成的图形比较不好看,很多属性没有找到!有什么好的属性希望大家补充!
package Chart;

import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.apache.commons.lang.WordUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.RingPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RectangleEdge;


public class BarChartDemo {
	public static void main(String[] args) throws IOException{ 
		 DefaultPieDataset dataset = getDataSet2(); 
		 	setTheme();  
        JFreeChart chart = ChartFactory.createRingChart(
        					"CS服务测试前十失败原因", 
        					dataset, 
        					true, 
        					false, 
                            false  
        					);
        
        RingPlot plot = (RingPlot) chart.getPlot();//获得图形面板
        
        plot.setIgnoreNullValues(true);  //忽略null值
        plot.setIgnoreZeroValues(true); //忽略0值
        
        plot.setBackgroundPaint(Color.WHITE);//设置画布背景颜色
        plot.setOutlineVisible(false);//设置绘图区边框是否可见
        plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})", NumberFormat.getNumberInstance(),
			new DecimalFormat("0.00%"))); //设置图例数据格式
        
        //设置生成图片的tooltip
        plot.setLabelLinksVisible(false);//设置图形和tooltip之间连线
        plot.setLabelLinkPaint(plot.getBackgroundPaint());
        plot.setLabelBackgroundPaint(plot.getBackgroundPaint());
		plot.setLabelOutlinePaint(plot.getBackgroundPaint());
		plot.setLabelShadowPaint(plot.getBackgroundPaint());
		plot.setLabelPaint(plot.getBackgroundPaint());
		//plot.setCircular(true);//设置饼图是否为原型
		plot.setLabelGap(0.0001D);
		//图形半径
		
        //图例样式的设定,图例含有M 和P 方法
        LegendTitle legendTitle = chart.getLegend();//获得图例标题
	   	legendTitle.setPosition(RectangleEdge.RIGHT);//图例右边显示
	   	legendTitle.setBorder(0, 0, 0, 0);//设置图例上下左右线
	   	legendTitle.setPadding(0, 0, 0, 50);
	   	//标题的距离的设定
	   	TextTitle title = chart.getTitle();	//设置标题居左的距离
	   	title.setMargin(0, -200, 0, 0);//标题距离上下左右的距离
	   	
        FileOutputStream fos_jpg = null; 
        try { 
            fos_jpg = new FileOutputStream("D:\\Ring.png"); 
            ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,chart,450,300,null); 
            System.out.println("图片生成完成");
        } finally { 
            try { 
                fos_jpg.close(); 
            } catch (Exception e) {
            	System.out.println(e.getMessage());
            } 
        } 
    }

	/** 
	  * <p>样式设定</p> 
	*/
	private static void setTheme() {
		//创建主题样式  
      StandardChartTheme standardChartTheme=new StandardChartTheme("CN"); 
      //设置标题
      standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,20));
      //设置图例的字体  
      standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,15));  
      //设置轴向的字体  
      standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,15));
      ChartFactory.setChartTheme(standardChartTheme);
	} 
/*
 * 基本数据集
 */
    private static DefaultPieDataset getDataSet2() { 
		 DefaultPieDataset dataset = new DefaultPieDataset(); 
		 
		String str = WordUtils.wrap("User8", 12);//设置过长换行
		 dataset.setValue("User1",2); 
		 dataset.setValue("User2",3); 
		 dataset.setValue("User3",4); 
		 dataset.setValue("User4",5); 
		 dataset.setValue("User5",6); 
		 dataset.setValue("User6",7); 
		 dataset.setValue(str,8); 
		 dataset.setValue("User7",9); 
		 dataset.setValue("carrier8",11); 
		 return dataset;
    } 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值