JFreeChart---饼图

来源:互联网 发布:vc6.0编程实例 编辑:程序博客网 时间:2024/04/30 20:16

源码:

/** * 饼状图 */@Testpublic void test3() {DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("苹果", 100);dataset.setValue("梨子", 200);dataset.setValue("葡萄", 300);dataset.setValue("香蕉", 400);dataset.setValue("橙子", 500);JFreeChart chart = ChartFactory.createPieChart("水果产量图", dataset);chart.setTitle(new TextTitle("水果产量", new Font("宋体", Font.BOLD, 12)));chart.setBackgroundPaint(Color.WHITE);//图表背景颜色chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 10));//3、获取图标区域对象PiePlot plot =  (PiePlot) chart.getPlot();plot.setBackgroundPaint(Color.WHITE);//颜色plot.setBackgroundAlpha(0.6f);//背景色透明度plot.setForegroundAlpha(0.9f);//前景色透明度plot.setLabelFont(new Font("宋体", Font.PLAIN, 10));plot.setCircular(true);//true:圆,false:椭圆plot.setNoDataMessage("无数据");plot.setLabelGap(0.2D);//显示数据,以及所占百分比//plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:({1}, {2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));try {ChartUtilities.writeChartAsJPEG(new FileOutputStream("E:/chart/pie_1.jpg"), chart, 400, 300, null);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}


源码:

/** * 饼状图 */@Testpublic void test4() {DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("苹果", 100);dataset.setValue("梨子", 200);dataset.setValue("葡萄", 300);dataset.setValue("香蕉", 400);dataset.setValue("橙子", 500);JFreeChart chart = ChartFactory.createPieChart("水果产量图", dataset);chart.setTitle(new TextTitle("水果产量", new Font("宋体", Font.BOLD, 12)));chart.setBackgroundPaint(Color.WHITE);//图表背景颜色chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 10));//3、获取图标区域对象PiePlot plot =  (PiePlot) chart.getPlot();plot.setBackgroundPaint(Color.WHITE);//颜色plot.setBackgroundAlpha(0.6f);//背景色透明度plot.setForegroundAlpha(0.9f);//前景色透明度plot.setLabelFont(new Font("宋体", Font.PLAIN, 10));plot.setCircular(true);//true:圆,false:椭圆plot.setNoDataMessage("无数据");plot.setLabelGap(0.2D);//显示数据,以及所占百分比plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:({1}, {2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));try {ChartUtilities.writeChartAsJPEG(new FileOutputStream("E:/chart/pie_2.jpg"), chart, 600, 560, null);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

源码:

/** * 饼状图 */@Testpublic void test5() {DefaultPieDataset dataset = new DefaultPieDataset();dataset.setValue("苹果", 100);dataset.setValue("梨子", 200);dataset.setValue("葡萄", 300);dataset.setValue("香蕉", 400);dataset.setValue("橙子", 500);JFreeChart chart = ChartFactory.createPieChart3D("水果产量图", dataset);chart.setTitle(new TextTitle("水果产量", new Font("宋体", Font.BOLD, 12)));chart.setBackgroundPaint(Color.WHITE);//图表背景颜色chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 10));//3、获取图标区域对象PiePlot plot =  (PiePlot) chart.getPlot();plot.setBackgroundPaint(Color.WHITE);//颜色plot.setBackgroundAlpha(0.6f);//背景色透明度plot.setForegroundAlpha(0.9f);//前景色透明度plot.setLabelFont(new Font("宋体", Font.PLAIN, 10));plot.setCircular(true);//true:圆,false:椭圆plot.setNoDataMessage("无数据");plot.setLabelGap(0.2D);//显示数据,以及所占百分比plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:({1}, {2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()));try {ChartUtilities.writeChartAsJPEG(new FileOutputStream("E:/chart/pie_3.jpg"), chart, 600, 560, null);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}



0 0
原创粉丝点击