protected JFreeChart createPie3DChart() throws JRException {
    JFreeChart jfreeChart = super.createPie3DChart();

    PiePlot3D piePlot3D = (PiePlot3D) jfreeChart.getPlot();
    if (piePlot3D.getLabelGenerator() != null) {
      piePlot3D.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
      piePlot3D.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
      piePlot3D.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    }
    piePlot3D.setDarkerSides(true);
    piePlot3D.setDepthFactor(0.07);
    // does not work for 3D
    //		piePlot3D.setShadowXOffset(5);
    //		piePlot3D.setShadowYOffset(10);
    //		piePlot3D.setShadowPaint(new GradientPaint(
    //				0,
    //				getChart().getHeight() / 2,
    //				new Color(41, 120, 162),
    //				0,
    //				getChart().getHeight(),
    //				Color.white)
    //		);

    PieDataset pieDataset = piePlot3D.getDataset();
    if (pieDataset != null) {
      for (int i = 0; i < pieDataset.getItemCount(); i++) {
        piePlot3D.setSectionOutlinePaint(
            pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);
      }
    }
    piePlot3D.setCircular(true);
    return jfreeChart;
  }
  protected JFreeChart createPieChart() throws JRException {
    JFreeChart jfreeChart = super.createPieChart();

    PiePlot piePlot = (PiePlot) jfreeChart.getPlot();
    if (piePlot.getLabelGenerator() != null) {
      piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT);
      piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT);
      piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT);
    }
    piePlot.setShadowXOffset(0);
    piePlot.setShadowYOffset(0);
    PieDataset pieDataset = piePlot.getDataset();
    if (pieDataset != null) {
      for (int i = 0; i < pieDataset.getItemCount(); i++) {
        piePlot.setSectionOutlinePaint(
            pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT);

        // makes pie colors darker
        // piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]);
      }
    }
    piePlot.setCircular(true);
    return jfreeChart;
  }
Пример #3
0
  /**
   * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
   *
   * @param g2 the graphics device.
   * @param area the area within which the plot should be drawn.
   * @param anchor the anchor point (<code>null</code> permitted).
   * @param parentState the state from the parent plot, if there is one.
   * @param info collects info about the drawing.
   */
  public void draw(
      Graphics2D g2,
      Rectangle2D area,
      Point2D anchor,
      PlotState parentState,
      PlotRenderingInfo info) {

    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    drawBackground(g2, area);
    drawOutline(g2, area);

    // check that there is some data to display...
    if (DatasetUtilities.isEmptyOrNull(getDataset())) {
      drawNoDataMessage(g2, area);
      return;
    }

    int pieCount = 0;
    if (getDataExtractOrder() == TableOrder.BY_ROW) {
      pieCount = getDataset().getRowCount();
    } else {
      pieCount = getDataset().getColumnCount();
    }

    // the columns variable is always >= rows
    int displayCols = (int) Math.ceil(Math.sqrt(pieCount));
    int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols);

    // swap rows and columns to match plotArea shape
    if (displayCols > displayRows && area.getWidth() < area.getHeight()) {
      int temp = displayCols;
      displayCols = displayRows;
      displayRows = temp;
    }

    prefetchSectionPaints();

    int x = (int) area.getX();
    int y = (int) area.getY();
    int width = ((int) area.getWidth()) / displayCols;
    int height = ((int) area.getHeight()) / displayRows;
    int row = 0;
    int column = 0;
    int diff = (displayRows * displayCols) - pieCount;
    int xoffset = 0;
    Rectangle rect = new Rectangle();

    for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) {
      rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height);

      String title = null;
      if (getDataExtractOrder() == TableOrder.BY_ROW) {
        title = getDataset().getRowKey(pieIndex).toString();
      } else {
        title = getDataset().getColumnKey(pieIndex).toString();
      }
      getPieChart().setTitle(title);

      PieDataset piedataset = null;
      PieDataset dd = new CategoryToPieDataset(getDataset(), getDataExtractOrder(), pieIndex);
      if (getLimit() > 0.0) {
        piedataset =
            DatasetUtilities.createConsolidatedPieDataset(dd, getAggregatedItemsKey(), getLimit());
      } else {
        piedataset = dd;
      }
      PiePlot piePlot = (PiePlot) getPieChart().getPlot();
      piePlot.setDataset(piedataset);
      piePlot.setPieIndex(pieIndex);

      // update the section colors to match the global colors...
      for (int i = 0; i < piedataset.getItemCount(); i++) {
        Comparable key = piedataset.getKey(i);
        Paint p;
        if (key.equals(getAggregatedItemsKey())) {
          p = getAggregatedItemsPaint();
        } else {
          p = (Paint) this.sectionPaints.get(key);
        }
        piePlot.setSectionPaint(key, p);
      }

      ChartRenderingInfo subinfo = null;
      if (info != null) {
        subinfo = new ChartRenderingInfo();
      }
      getPieChart().draw(g2, rect, subinfo);
      if (info != null) {
        info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection());
        info.addSubplotInfo(subinfo.getPlotInfo());
      }

      ++column;
      if (column == displayCols) {
        column = 0;
        ++row;

        if (row == displayRows - 1 && diff != 0) {
          xoffset = (diff * width) / 2;
        }
      }
    }
  }