乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      jFreeChart學(xué)習(xí)筆記

       桑枯海 2013-08-06

      一  JFreeChart生成餅狀圖

      實(shí)現(xiàn)的思路

      1、初始化圖表數(shù)據(jù)
      2、獲得圖表數(shù)據(jù)集DefaultPieDataset
      3、利用chart工廠創(chuàng)建一個(gè)jfreechart實(shí)例
         JFreeChart chart = ChartFactory.createPieChart3D(title, // 圖表標(biāo)題
              dataset, // 圖表數(shù)據(jù)集
              true, // 是否顯示圖例
              false, // 是否生成工具(提示)
              false // 是否生成URL鏈接
              );
      4、通過(guò)TextTitle類(lèi)設(shè)置餅圖的標(biāo)題與字體:
            void setFont(Font font)標(biāo)題字體
            void setPaint(Paint paint)標(biāo)題字體顏色
            void setText(String title)標(biāo)題內(nèi)容
      5、通過(guò)LegendTitle類(lèi)設(shè)置圖例的字體:
            void setItemFont(Font font)標(biāo)題字體
      6、獲得餅圖實(shí)例PiePlot,設(shè)置餅圖參數(shù):
            void setLabelFont(Font font)標(biāo)簽字體
            void setForegroundAlpha(float alpha)指定圖片的透明度(0.0-1.0)
            void setLabelGenerator(PieSectionLabelGenerator generator)分類(lèi)標(biāo)簽的格式,設(shè)置成null則整個(gè)標(biāo)簽包括連接結(jié)都不顯示
            void setStartAngle(double angle)餅圖的初始角度
      源代碼


      import java.awt.Color;
      import java.awt.Font;
      import java.text.DecimalFormat;
      import java.text.NumberFormat;
      import org.jfree.chart.ChartFactory;
      import org.jfree.chart.ChartFrame;
      import org.jfree.chart.JFreeChart;
      import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
      import org.jfree.chart.plot.PiePlot;
      import org.jfree.chart.title.LegendTitle;
      import org.jfree.chart.title.TextTitle;
      import org.jfree.data.general.DefaultPieDataset;
      public class CreatePieChart {
          /**
          * 獲得數(shù)據(jù)集。
          * @return org.jfree.data.general.DefaultPieDataset
          */
          private static DefaultPieDataset getDataSet() {
              DefaultPieDataset dfp = new DefaultPieDataset();
              dfp.setValue("研發(fā)人員", 35);
              dfp.setValue("市場(chǎng)策劃人員", 10);
              dfp.setValue("市場(chǎng)推廣人員", 25);
              dfp.setValue("網(wǎng)絡(luò)維護(hù)人員", 5);
              dfp.setValue("財(cái)務(wù)人員", 15);
              return dfp;
          }
          /**
           * 生成餅狀圖。
           */
          public static void makePieChart3D() {
              String title = "餅狀圖";
              // 獲得數(shù)據(jù)集
              DefaultPieDataset dataset = getDataSet();
              // 利用chart工廠創(chuàng)建一個(gè)jfreechart實(shí)例
              JFreeChart chart = ChartFactory.createPieChart3D(title,   // 圖表標(biāo)題
                      dataset,   // 圖表數(shù)據(jù)集
                      true,      // 是否顯示圖例
                      false,     // 是否生成工具(提示)
                      false      // 是否生成URL鏈接
                      );
              // 設(shè)置pieChart的標(biāo)題與字體
              Font font = new Font("宋體", Font.BOLD, 25);
              TextTitle textTitle = new TextTitle(title);
              textTitle.setFont(font);
              chart.setTitle(textTitle);
              chart.setTextAntiAlias(false);
              // 設(shè)置背景色
              chart.setBackgroundPaint(new Color(255, 255, 255));
              // 設(shè)置圖例字體
              LegendTitle legend = chart.getLegend(0);
              legend.setItemFont(new Font("宋體", 1, 15));
              // 設(shè)置標(biāo)簽字體
              PiePlot plot = (PiePlot) chart.getPlot();
              plot.setLabelFont(new Font("宋體", Font.TRUETYPE_FONT, 12));
              // 指定圖片的透明度(0.0-1.0)
              plot.setForegroundAlpha(0.95f);
              // 圖片中顯示百分比:自定義方式,{0} 表示選項(xiàng), {1} 表示數(shù)值, {2} 表示所占比例 ,小數(shù)點(diǎn)后兩位
              plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
                      "{0}={1}({2})", NumberFormat.getNumberInstance(),
                      new DecimalFormat("0.00%")));
              // 圖例顯示百分比:自定義方式, {0} 表示選項(xiàng), {1} 表示數(shù)值, {2} 表示所占比例
              plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
              // 設(shè)置第一個(gè)餅塊截面開(kāi)始的位置,默認(rèn)是12點(diǎn)鐘方向
              plot.setStartAngle(90);
              /***********************************************************/
              ChartFrame frame = new ChartFrame(title, chart, true);
              frame.pack();
              frame.setVisible(true);
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              // 3D餅狀圖
              makePieChart3D();
          }
      }
       
       
       
      二  JFreeChart生成柱狀圖
      實(shí)現(xiàn)的思路
      1、初始化圖表數(shù)據(jù)
      2、獲得圖表數(shù)據(jù)集CategoryDataset
      3、利用chart工廠創(chuàng)建一個(gè)jfreechart實(shí)例
         JFreeChart chart = ChartFactory.createBarChart3D(title, // 圖表標(biāo)題
              "X軸",                     // X軸的顯示標(biāo)簽
              "Y軸",                     // Y軸的顯示標(biāo)簽
              dataset,                   // 數(shù)據(jù)集
              PlotOrientation.VERTICAL,  // 圖表方向:水平、垂直
              true,                      // 是否顯示圖例
              true,                      // 是否生成工具(提示)
              true                       // 是否生成URL鏈接
              );
      4、通過(guò)TextTitle類(lèi)設(shè)置餅圖的標(biāo)題與字體:
            void setFont(Font font)標(biāo)題字體
            void setPaint(Paint paint)標(biāo)題字體顏色
            void setText(String title)標(biāo)題內(nèi)容
      5、獲得柱狀圖實(shí)例CategoryPlot:
            CategoryPlot plot = chart.getCategoryPlot();
      6、獲得橫軸(CategoryAxis)并設(shè)置格式
            CategoryAxis categoryAxis = plot.getDomainAxis();
            void setLabelFont(Font font)橫軸標(biāo)簽字體
            void setTickLabelFont(Font font)橫軸標(biāo)記字體
      7、獲得縱軸(NumberAxis)并設(shè)置格式
            NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
            void setLabelFont(Font font)縱軸標(biāo)簽字體
      源代碼

      import org.jfree.chart.ChartFactory;
      import org.jfree.chart.ChartFrame;
      import org.jfree.chart.JFreeChart;
      import org.jfree.chart.axis.CategoryAxis;
      import org.jfree.chart.axis.NumberAxis;
      import org.jfree.chart.plot.CategoryPlot;
      import org.jfree.chart.plot.PlotOrientation;
      import org.jfree.chart.title.LegendTitle;
      import org.jfree.chart.title.TextTitle;
      import org.jfree.data.category.CategoryDataset;
      import org.jfree.data.general.DatasetUtilities;
      public class CreateBarChart {
          /**
           * 獲得數(shù)據(jù)集。
           * @return org.jfree.data.category.CategoryDataset
           */
          private static CategoryDataset getDataset() {
              double[][] data = new double[][] { { 751, 800, 260, 600, 200 },
                  { 400, 560, 240, 300, 150 }, { 600, 450, 620, 220, 610 } };
              String[] rowKeys = { "CPU", "硬盤(pán)", "內(nèi)存" };
              String[] columnKeys = { "北京", "上海", "廣州", "南京", "深圳" };
              CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
                  rowKeys, columnKeys, data);
              return dataset;
          }
          /**
           * 生成柱狀圖。
           */
          public static void makeBarChart3D() {
              String title = "電腦配件三月銷(xiāo)量";
              // 獲得數(shù)據(jù)集
              CategoryDataset dataset = getDataset();
              JFreeChart chart = ChartFactory.createBarChart3D(title, // 圖表標(biāo)題
                  "配件",                      // 目錄軸的顯示標(biāo)簽
                  "銷(xiāo)量",                      // 數(shù)值軸的顯示標(biāo)簽
                  dataset,                     // 數(shù)據(jù)集
                  PlotOrientation.VERTICAL,    // 圖表方向:水平、垂直
                  true,                        // 是否顯示圖例
                  true,                        // 是否生成工具(提示)
                  true                         // 是否生成URL鏈接
              );
              // 設(shè)置標(biāo)題字體
              Font font = new Font("宋體", Font.BOLD, 18);
              TextTitle textTitle = new TextTitle(title);
              textTitle.setFont(font);
              chart.setTitle(textTitle);
              chart.setTextAntiAlias(false);
              // 設(shè)置背景色
              chart.setBackgroundPaint(new Color(255, 255, 255));
              // 設(shè)置圖例字體
              LegendTitle legend = chart.getLegend(0);
              legend.setItemFont(new Font("宋體", Font.TRUETYPE_FONT, 14));
              // 獲得柱狀圖的Plot對(duì)象
              CategoryPlot plot = chart.getCategoryPlot();
              // 取得橫軸
              CategoryAxis categoryAxis = plot.getDomainAxis();
              // 設(shè)置橫軸顯示標(biāo)簽的字體
              categoryAxis.setLabelFont(new Font("宋體", Font.BOLD, 16));
              // 設(shè)置橫軸標(biāo)記的字體
              categoryAxis.setTickLabelFont(new Font("宋休", Font.TRUETYPE_FONT, 16));
              // 取得縱軸
              NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
              // 設(shè)置縱軸顯示標(biāo)簽的字體
              numberAxis.setLabelFont(new Font("宋體", Font.BOLD, 16));
              /**************************************************************/
              ChartFrame frame = new ChartFrame(title, chart, true);
              frame.pack();
              frame.setVisible(true);
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              // 3D柱狀圖
              makeBarChart3D();
          }
      }
       
       
       
      三 JFreeChart生成折線圖
      實(shí)現(xiàn)的思路
      1、初始化圖表數(shù)據(jù)
      2、獲得圖表數(shù)據(jù)集CategoryDataset
      3、利用chart工廠創(chuàng)建一個(gè)jfreechart實(shí)例
         JFreeChart chart = ChartFactory.createLineChart(title, // 圖表標(biāo)題
              "X軸",                     // X軸的顯示標(biāo)簽
              "Y軸",                     // Y軸的顯示標(biāo)簽
              dataset,                   // 數(shù)據(jù)集
              PlotOrientation.VERTICAL,  // 圖表方向:水平、垂直
              true,                      // 是否顯示圖例
              true,                      // 是否生成工具(提示)
              false                      // 是否生成URL鏈接
              );
      4、通過(guò)TextTitle類(lèi)設(shè)置餅圖的標(biāo)題與字體:
            void setFont(Font font)標(biāo)題字體
            void setPaint(Paint paint)標(biāo)題字體顏色
            void setText(String title)標(biāo)題內(nèi)容
      5、獲得折線圖實(shí)例CategoryPlot
            CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
            void setDomainGridlinesVisible(boolean flag)設(shè)置X軸網(wǎng)格是否中見(jiàn)
            void setRangeGridlinesVisible(boolean flag)設(shè)置Y軸網(wǎng)格是否可見(jiàn)
            void setBackgroundPaint(Color color)設(shè)置背景色
      6、獲得橫軸(CategoryAxis)并設(shè)置格式
            CategoryAxis categoryAxis = plot.getDomainAxis();
            void setLabelFont(Font font)橫軸標(biāo)簽字體
            void setTickLabelFont(Font font)橫軸標(biāo)記字體
      7、獲得縱軸(NumberAxis)并設(shè)置格式
            NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
            void setLabelFont(Font font)縱軸標(biāo)簽字體
      源代碼

      importjava.awt.Color;
      importjava.awt.Font;
      importorg.jfree.chart.ChartFactory;
      importorg.jfree.chart.ChartFrame;
      importorg.jfree.chart.JFreeChart;
      importorg.jfree.chart.axis.CategoryAxis;
      importorg.jfree.chart.axis.CategoryLabelPositions;
      importorg.jfree.chart.axis.NumberAxis;
      importorg.jfree.chart.plot.CategoryPlot;
      importorg.jfree.chart.plot.PlotOrientation;
      importorg.jfree.chart.renderer.category.LineAndShapeRenderer;
      importorg.jfree.chart.title.LegendTitle;
      importorg.jfree.chart.title.TextTitle;
      importorg.jfree.data.category.CategoryDataset;
      importorg.jfree.data.general.DatasetUtilities;
      public class CreateLineChart {
          /**
           * 獲得數(shù)據(jù)集。
           * @return org.jfree.data.category.CategoryDataset
           */
          private static CategoryDataset getDataset() {
              double[][] data = new double[][] { { 751, 800, 260, 600, 200 },
                      { 400, 560, 240, 300, 150 }, { 600, 450, 620, 220, 610 } };
              String[] rowKeys = { "CPU", "硬盤(pán)", "內(nèi)存" };
              String[] columnKeys = { "北京", "上海", "廣州", "南京", "深圳" };
              CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
                      rowKeys, columnKeys, data);
              return dataset;
          }
          /**
           * 生成折線圖。
           */
          public static void makeLineChart() {
              String title = "電腦配件三月銷(xiāo)量";
              // 獲得數(shù)據(jù)集
              CategoryDataset dataset = getDataset();
              JFreeChart chart = ChartFactory.createLineChart(title, // 圖表標(biāo)題
                      "配件",                    // 目錄軸的顯示標(biāo)簽
                      "銷(xiāo)量",                    // 數(shù)值軸的顯示標(biāo)簽
                      dataset,                   // 數(shù)據(jù)集
                      PlotOrientation.VERTICAL,  // 圖表方向:水平、垂直
                      true,                      // 是否顯示圖例
                      true,                      // 是否生成工具(提示)
                      false                      // 是否生成URL鏈接
                      );
              chart.setTextAntiAlias(false);
              // 設(shè)置背景色
              chart.setBackgroundPaint(Color.WHITE);
              // 設(shè)置圖標(biāo)題的字體
              Font font = new Font("宋體", Font.BOLD, 20);
              TextTitle textTitle = new TextTitle(title);
              textTitle.setFont(font);
              chart.setTitle(textTitle);
              // 設(shè)置X軸Y軸的字體
              Font labelFont = new Font("宋體", Font.BOLD, 16);
              chart.setBackgroundPaint(Color.WHITE);
              // 設(shè)置圖例字體
              LegendTitle legend = chart.getLegend(0);
              legend.setItemFont(new Font("宋體", Font.TRUETYPE_FONT, 14));
              // 獲得plot
              CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
              // x軸 分類(lèi)軸網(wǎng)格是否可見(jiàn)
              categoryplot.setDomainGridlinesVisible(true);
              // y軸 數(shù)據(jù)軸網(wǎng)格是否可見(jiàn)
              categoryplot.setRangeGridlinesVisible(true);
              // 虛線色彩
              categoryplot.setRangeGridlinePaint(Color.WHITE);
              // 虛線色彩
              categoryplot.setDomainGridlinePaint(Color.WHITE);
              // 設(shè)置背景色
              categoryplot.setBackgroundPaint(Color.lightGray);
              // 設(shè)置軸和面板之間的距離
              CategoryAxis domainAxis = categoryplot.getDomainAxis();
              // 設(shè)置橫軸標(biāo)簽標(biāo)題字體
              domainAxis.setLabelFont(labelFont);
              // 設(shè)置橫軸數(shù)值標(biāo)簽字體
              domainAxis.setTickLabelFont(new Font("宋體", Font.TRUETYPE_FONT, 14));
              // 橫軸上的
              domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
              // 設(shè)置距離圖片左端距離
              domainAxis.setLowerMargin(0.0);
              // 設(shè)置距離圖片右端距離
              domainAxis.setUpperMargin(0.0);
              NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
              // 設(shè)置縱軸顯示標(biāo)簽的字體
              numberaxis.setLabelFont(labelFont);
              numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
              numberaxis.setAutoRangeIncludesZero(true);
              // 獲得renderer
              LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
                      .getRenderer();
              // series 點(diǎn)(即數(shù)據(jù)點(diǎn))可見(jiàn)
              lineandshaperenderer.setBaseShapesVisible(true);
              // series 點(diǎn)(即數(shù)據(jù)點(diǎn))間有連線可見(jiàn)
              lineandshaperenderer.setBaseLinesVisible(true);
              /*******************************************************/
              ChartFrame frame = new ChartFrame(title, chart, true);
              frame.pack();
              frame.setVisible(true);
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              // 曲線圖
              makeLineChart();
          }
      }
       
       四 JFreeChart生成時(shí)序圖
      實(shí)現(xiàn)的思路
      1、實(shí)例化TimeSeries對(duì)象
         TimeSeries timeseries = new TimeSeries("Data");
      2、創(chuàng)建TimeSeriesCollection集合對(duì)象
         TimeSeriesCollection dataset = new TimeSeriesCollection(timeseries);
      3、利用chart工廠創(chuàng)建一個(gè)jfreechart實(shí)例
         JFreeChart chart = ChartFactory.createBarChart3D(title, // 圖表標(biāo)題
              "X軸",                     // X軸的顯示標(biāo)簽
              "Y軸",                     // Y軸的顯示標(biāo)簽
              dataset,                   // 數(shù)據(jù)集
              true,                      // 是否顯示圖例
              true,                      // 是否生成工具(提示)
              true                       // 是否生成URL鏈接
              );
      4、通過(guò)TextTitle類(lèi)設(shè)置餅圖的標(biāo)題與字體:
            void setFont(Font font)標(biāo)題字體
            void setPaint(Paint paint)標(biāo)題字體顏色
            void setText(String title)標(biāo)題內(nèi)容
      5、通過(guò)LegendTitle類(lèi)設(shè)置圖例的字體:
            void setItemFont(Font font)標(biāo)題字體
      6、獲得時(shí)序圖實(shí)例XYPlot:
            XYPlot plot = chart.getXYPlot();
      7、獲取X軸對(duì)象
            DateAxis axis = (DateAxis) plot.getDomainAxis();
            void setDateFormatOverride(DateFormat formatter)設(shè)置日期顯示格式
            void setLabelFont(Font font)設(shè)置X軸標(biāo)簽字體
      8、獲取Y軸對(duì)象
            NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
            void setLabelFont(Font font)設(shè)置Y軸標(biāo)簽字體
      源代碼

      import java.awt.Color;
      import java.awt.Font;
      import java.text.SimpleDateFormat;
      import org.jfree.chart.ChartFactory;
      import org.jfree.chart.ChartFrame;
      import org.jfree.chart.JFreeChart;
      import org.jfree.chart.axis.DateAxis;
      import org.jfree.chart.axis.NumberAxis;
      import org.jfree.chart.plot.XYPlot;
      import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
      import org.jfree.chart.title.LegendTitle;
      import org.jfree.chart.title.TextTitle;
      import org.jfree.data.time.Day;
      import org.jfree.data.time.TimeSeries;
      import org.jfree.data.time.TimeSeriesCollection;
      public class CreateTimeSeriesChart {
          public static void makeTimeSeriesChart() {
              // 實(shí)例化TimeSeries對(duì)象
              TimeSeries timeseries = new TimeSeries("Data");
              // 實(shí)例化Day
              Day day = new Day(1,1,2009);
              double d = 3000D;
              // 添加一年365天的數(shù)據(jù)
              for(int i = 0 ; i < 365 ; i++){
                  // 創(chuàng)建隨機(jī)數(shù)據(jù)
                  d = d+(Math.random() - 0.5) * 10;
                  // 向數(shù)據(jù)集合中添加數(shù)據(jù)
                  timeseries.add(day,d);
                  day = (Day)day.next();
              }
              // 創(chuàng)建TimeSeriesCollection集合對(duì)象
              TimeSeriesCollection dataset = new TimeSeriesCollection(timeseries);
              // 生成時(shí)序圖
              JFreeChart chart = ChartFactory.createTimeSeriesChart("上證指數(shù)時(shí)序圖",//標(biāo)題
                     "日期",    //時(shí)間軸標(biāo)簽
                     "指數(shù)",    //數(shù)據(jù)軸標(biāo)簽
                     dataset,   //數(shù)據(jù)集合
                     true,      //是否顯示圖例標(biāo)識(shí)
                     true,      //是否顯示tooltips
                     false);    //是否支持超鏈接
              String title = "上證指數(shù)時(shí)序圖";
              // 設(shè)置圖例字體
              LegendTitle legend = chart.getLegend(0);
              legend.setItemFont(new Font("宋體", Font.TRUETYPE_FONT, 15));
              // 設(shè)置標(biāo)題字體
              Font font = new Font("宋體", Font.BOLD, 20);
              TextTitle textTitle = new TextTitle(title);
              textTitle.setFont(font);
              chart.setTitle(textTitle);
              // Plot 對(duì)象的獲取操作
              XYPlot plot = chart.getXYPlot();
              // X 軸對(duì)象的獲取操作
              DateAxis axis = (DateAxis) plot.getDomainAxis();
              // 設(shè)置日期顯示格式
              axis.setDateFormatOverride(new SimpleDateFormat("MM-dd-yyyy"));
              // 設(shè)置X軸標(biāo)簽字體
              axis.setLabelFont(new Font("宋體", Font.BOLD, 14));
              // Y 軸對(duì)象的獲取操作
              NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
              // 設(shè)置Y軸標(biāo)簽字體
              numAxis.setLabelFont(new Font("宋體", Font.BOLD, 14));
              /***************************************************************/
              ChartFrame cf = new ChartFrame("時(shí)序圖", chart);
              cf.pack();
              cf.setVisible(true);
          }
          /**
           * @param args
           */
          public static void main(String[] args) {
              // 時(shí)序圖
              makeTimeSeriesChart();
          }
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多