熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

實例編程:JFreechart 的一些用法

2013-11-23 18:38:45  來源: Java核心技術 

  public abstract class AbstractStatistic implements Statistic {

  /**

  * 創建統計圖形

  *

  * @param columnKeys

  * 關鍵字數組

  * @param data

  * 數據數組

  * @param title

  * 標題

  * @param session

  * @param rowKeys

  * 行關鍵字

  * @param showType

  * @return

  */

  public String createStatisticImg(String[] columnKeys double[][] data

  String title HttpSession session String[] rowKeys String showType) {

  try {

  JFreeChart chart = null;

  if(showTypeequals()){

  chart = createBarChartD(datacolumnKeysrowKeystitle);

  }

  if(showTypeequals()){

  chart = createLineChart(datacolumnKeysrowKeystitle);

  }

  if(showTypeequals()){

  chart = createAreaChart(datacolumnKeysrowKeystitle);

  }

  if(showTypeequals()){

  chart = createLineChartD(data columnKeys rowKeys title);

  }

  String filename = ServletUtilitiessaveChartAsPNG(chart

  null session);

  return filename;

  } catch (IOException e) {

  // TODO Autogenerated catch block

  eprintStackTrace();

  }

  return ;

  }

  public JFreeChart createBarChartD(double[][] data String[] columnKeys String[] rowKeysString title){

  CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

  rowKeys columnKeys data);

  JFreeChart chart = ChartFactorycreateBarChartD(title// 分布與對比圖

   null dataset PlotOrientationVERTICAL true false

  false);

  chartsetBackgroundPaint(ColorWHITE);// 設置整張圖片背景色

  CategoryPlot plot = chartgetCategoryPlot();

  plotsetBackgroundPaint(Colorgray);// 設置圖形區域背景色

  // 設置是否顯示垂直網格線

  plotsetDomainGridlinesVisible(true);

  // 設置是否顯示水平網格線

  plotsetRangeGridlinesVisible(true);

  CategoryAxis domainAxis = plotgetDomainAxis();

  /*設置X軸標題的傾斜程度*/

  domainAxissetCategoryLabelPositions(CategoryLabelPositionsSTANDARD);

  domainAxissetMaximumCategoryLabelLines();

  domainAxissetTickLabelFont(new Font(黑體 FontPLAIN ));

  plotsetDomainAxis(domainAxis);

  ValueAxis rangeAxis = plotgetRangeAxis();

  // 設置最高的一個 Item 與圖片頂端的距離

  rangeAxissetUpperMargin();

  // 設置最低的一個 Item 與圖片底端的距離

  rangeAxissetLowerMargin();

  plotsetRangeAxis(rangeAxis);

  BarRendererD renderer = new BarRendererD();

  renderersetBaseOutlinePaint(ColorBLACK);

  // 設置 Wall 的顏色

  renderersetWallPaint(Colorgray);

  // 設置每種柱的顏色

  renderersetSeriesPaint( new Color( ));

  renderersetSeriesPaint( new Color( ));

  renderersetSeriesPaint( new Color( ));

  // 置每種柱的 Outline 顏色

  renderersetSeriesOutlinePaint( ColorBLACK);

  renderersetSeriesOutlinePaint( ColorBLACK);

  renderersetSeriesOutlinePaint( ColorBLACK);

  // 設置每個地區所包含的平行柱的之間距離

  renderersetItemMargin();

  // 顯示每個柱的數值並修改該數值的字體屬性

  // renderersetSeriesItemLabelGenerator(new

  // StandardCategoryItemLabelGenerator(##%javatextNumberFormatgetPercentInstance()));

  renderer

  setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

  renderersetItemLabelFont(new Font(黑體 FontPLAIN ));

  renderersetItemLabelsVisible(true);

  // 設置標簽顯示位置不加這句將顯示在柱體內

  renderersetPositiveItemLabelPosition(new ItemLabelPosition(

  ItemLabelAnchorOUTSIDE TextAnchorBOTTOM_CENTER));

  plotsetRenderer(renderer);

  // 設置柱的透明度

  plotsetForegroundAlpha(f);

  // 設置地區銷量的顯示位置

  plotsetDomainAxisLocation(AxisLocationBOTTOM_OR_LEFT);

  plotsetRangeAxisLocation(AxisLocationBOTTOM_OR_LEFT);

  return chart;

  }

  public JFreeChart createLineChart(double[][] data String[] columnKeys String[] rowKeysString title){

  CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

  rowKeys columnKeys data);

  JFreeChart chart = ChartFactorycreateLineChart(title// 區域分布與對比圖

   null dataset PlotOrientationVERTICAL true false

  false);

  CategoryPlot plot = chartgetCategoryPlot();

  CategoryAxis domainAxis = plotgetDomainAxis();

  /*設置X軸標題的傾斜程度*/

  domainAxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

  domainAxissetTickLabelFont(new Font(黑體 FontPLAIN ));

  return chart;

  }

  public JFreeChart createLineChartD(double[][] data String[] columnKeys String[] rowKeysString title){

  CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

  rowKeys columnKeys data);

  JFreeChart chart = ChartFactorycreateLineChartD(title// 區域分布與對比圖

   null dataset PlotOrientationVERTICAL true false

  false);

  CategoryPlot plot = chartgetCategoryPlot();

  CategoryAxis domainAxis = plotgetDomainAxis();

  /*設置X軸標題的傾斜程度*/

  domainAxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

  domainAxissetTickLabelFont(new Font(黑體 FontPLAIN ));

  return chart;

  }

  public JFreeChart createAreaChart(double[][] data String[] columnKeys String[] rowKeysString title){

  CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

  rowKeys columnKeys data);

  JFreeChart chart = ChartFactorycreateAreaChart(title 統計時間 統計數量 dataset PlotOrientationVERTICAL true true false);

  chartsetBackgroundPaint(Colorwhite);

  CategoryPlot categoryplot = (CategoryPlot)chartgetPlot();

  categoryplotsetForegroundAlpha(F);

  categoryplotsetAxisOffset(new RectangleInsets(D D D D));

  categoryplotsetBackgroundPaint(ColorlightGray);

  categoryplotsetDomainGridlinesVisible(true);

  categoryplotsetDomainGridlinePaint(Colorwhite);

  categoryplotsetRangeGridlinesVisible(true);

  categoryplotsetRangeGridlinePaint(Colorwhite);

  CategoryAxis categoryaxis = categoryplotgetDomainAxis();

  categoryaxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

  categoryaxissetLowerMargin(D);

  categoryaxissetUpperMargin(D);

  categoryaxisaddCategoryLabelToolTip(Type The first type);

  categoryaxisaddCategoryLabelToolTip(Type The second type);

  categoryaxisaddCategoryLabelToolTip(Type The third type);

  NumberAxis numberaxis = (NumberAxis)categoryplotgetRangeAxis();

  numberaxissetStandardTickUnits(NumberAxiscreateIntegerTickUnits());

  numberaxissetLabelAngle(D);

  return chart;


From:http://tw.wingwit.com/Article/program/Java/hx/201311/25518.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.