JFreechart环形图

来源:互联网 发布:胡家窝棚数据分析 编辑:程序博客网 时间:2024/05/29 15:09
生成的图形比较不好看,很多属性没有找到!有什么好的属性希望大家补充!
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;    } }

原创粉丝点击