廉頗老矣,尚能飯否

          java:從技術(shù)到管理

          常用鏈接

          統(tǒng)計

          最新評論

          jfreechart應(yīng)用_例題_生成餅狀圖(不顯示,只生成文件)_可以直接運行

          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;

          /**
           * 生成餅狀圖(不顯示,只生成文件)
           *導(dǎo)入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("超出實檢上限總捆數(shù)" + "\n" + a + "根\n", a);
            pds.setValue("實檢范圍內(nèi)總捆數(shù)" + "\n" + b + "根\n", b);
            pds.setValue("超出實檢下限總捆數(shù)" + "\n" + c + "根\n", c);
            JFreeChart jfreechart = ChartFactory.createPieChart("棒材異常磅單超重捆數(shù)信息圖" + "\n" + a + "+"+ b + "+" + c + "=" + count, pds,
              false, true, false);
            PiePlot pieplot = (PiePlot) jfreechart.getPlot();
            pieplot.setLabelFont(new Font("宋體", 0, 12));
            pieplot.setNoDataMessage("無數(shù)據(jù)");
            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 閱讀(1867) 評論(0)  編輯  收藏 所屬分類: JFreeChart

          主站蜘蛛池模板: 岱山县| 象山县| 扶风县| 东台市| 苍梧县| 南木林县| 谷城县| 道孚县| 安吉县| 锦屏县| 璧山县| 秀山| 德钦县| 台江县| 青州市| 平陆县| 巫山县| 特克斯县| 五峰| 越西县| 甘孜| 五大连池市| 澄城县| 翁牛特旗| 吉隆县| 宝坻区| 宣恩县| 水城县| 凯里市| 砚山县| 宁海县| 金门县| 喜德县| 定安县| 青铜峡市| 策勒县| 富源县| 泰顺县| 浮山县| 安多县| 资溪县|