廉颇老矣,尚能饭否

java:从技术到管理

常用链接

统计

最新评论

jfreechart应用_例题_生成饼状图(不显示,只生成文件)_可以直接运行

package pkg;

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.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.block.BlockContainer;
import org.jfree.chart.block.BorderArrangement;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.HorizontalAlignment;
import org.jfree.ui.RectangleEdge;

/**
 * 生成饼状图(不显示,只生成文件)
 *导入jar包 jaxen-1.1.1.jar,jcommon-1.0.12.jar,jfreechart-1.0.9.jar
 *
 * @author liudecai_zan@126.com
 *
 */
public class Test {
 public static void main(String[] args) throws IOException {
  DefaultPieDataset pds = new DefaultPieDataset();
  int a = 25;
  int b = 35;
  int c = 15;
  int count = a + b + c;
  pds.setValue("超出实检上限总捆数" + "\n" + a + "根\n", a);
  pds.setValue("实检范围内总捆数" + "\n" + b + "根\n", b);
  pds.setValue("超出实检下限总捆数" + "\n" + c + "根\n", c);
  JFreeChart jfreechart = ChartFactory.createPieChart("棒材异常磅单超重捆数信息图" + "\n" + a + "+"+ b + "+" + c + "=" + count, pds,
    false, true, false);
  PiePlot pieplot = (PiePlot) jfreechart.getPlot();
  pieplot.setLabelFont(new Font("宋体", 0, 12));
  pieplot.setNoDataMessage("无数据");
  pieplot.setCircular(true);
  pieplot.setLabelGap(0.02D);
  pieplot.setBackgroundPaint(new Color(199, 237, 204));

  pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator(
    "{0} {2}", NumberFormat.getNumberInstance(), new DecimalFormat(
      "0.00%")));
  LegendTitle legendtitle = new LegendTitle(jfreechart.getPlot());
  BlockContainer blockcontainer = new BlockContainer(
    new BorderArrangement());
  BlockContainer blockcontainer1 = legendtitle.getItemContainer();
  blockcontainer1.setPadding(2D, 10D, 5D, 2D);
  blockcontainer.add(blockcontainer1);
  legendtitle.setWrapper(blockcontainer);
  legendtitle.setPosition(RectangleEdge.RIGHT);
  legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
  jfreechart.addSubtitle(legendtitle);
  jfreechart.setBackgroundPaint(new Color(199, 237, 204));
  FileOutputStream fos_jpg = null;
  try {
   fos_jpg = new FileOutputStream("F:\\steelBar.jpg");
   ChartUtilities
     .writeChartAsJPEG(fos_jpg, jfreechart, 1000, 800, null);
  } finally {
   try {
    fos_jpg.close();
   } catch (Exception e) {

   }
  }
  System.out.println("ok");
 }

}



柳德才
13691193654
18942949207
QQ:422157370
liudecai_zan@126.com
湖北-武汉-江夏-庙山

posted on 2009-01-09 00:34 liudecai_zan@126.com 阅读(1859) 评论(0)  编辑  收藏 所属分类: JFreeChart


只有注册用户登录后才能发表评论。


网站导航: