public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report =
        ChartFactory.createStackedBarChart(
            this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(),
            this.datasetStrategy.getXAxisLabel(),
            categorydataset,
            PlotOrientation.HORIZONTAL,
            true,
            true,
            false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
        || datasetStrategy instanceof MultiCloverBarChartStrategy) {
      numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
      numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setItemLabelsVisible(true);
    stackedbarrenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setItemLabelFont(
        StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height =
        (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT
            + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
      super.setHeight(height);
    } else {
      super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
      stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }
  }
Exemplo n.º 2
0
 private static JFreeChart createChart(CategoryDataset categorydataset, String title) {
   JFreeChart jfreechart =
       ChartFactory.createStackedBarChart(
           title, "分类:区域", "短信数", categorydataset, PlotOrientation.HORIZONTAL, true, true, false);
   jfreechart.setBackgroundPaint(Color.white);
   CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
   categoryplot.setBackgroundPaint(Color.lightGray);
   categoryplot.setRangeGridlinePaint(Color.white);
   categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
   StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
   stackedbarrenderer.setDrawBarOutline(false);
   stackedbarrenderer.setMaximumBarWidth(0.1);
   stackedbarrenderer.setItemLabelsVisible(true);
   return jfreechart;
 }