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;
  }
예제 #2
0
 private static JFreeChart createChart(PieDataset dataset, String title) {
   JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false);
   PiePlot3D plot = (PiePlot3D) chart.getPlot();
   plot.setStartAngle(290.0d);
   plot.setDirection(Rotation.CLOCKWISE);
   plot.setForegroundAlpha(JFreeChart.DEFAULT_BACKGROUND_IMAGE_ALPHA);
   return chart;
 }
예제 #3
0
 private static JFreeChart createChart(PieDataset piedataset) {
   JFreeChart jfreechart =
       ChartFactory.createPieChart3D("Statitic", piedataset, true, false, false);
   PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
   pieplot3d.setStartAngle(270D);
   pieplot3d.setDirection(Rotation.ANTICLOCKWISE);
   pieplot3d.setForegroundAlpha(0.6F);
   return jfreechart;
 }
  // creates JFreeChart pie chart with data set
  private JFreeChart createPieChart(PieDataset dataSet, String title) {
    JFreeChart chart =
        ChartFactory.createPieChart3D(
            title, // chart title
            dataSet, // data
            true, // include legend
            true, false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    return chart;
  }
예제 #5
0
  @Override
  public JFreeChart createChart(PieDataset pieDataSet, boolean createLegend) {
    JFreeChart chart =
        ChartFactory.createPieChart3D(
            null,
            pieDataSet,
            createLegend, // legend
            true,
            false);

    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setForegroundAlpha(0.5f);

    return chart;
  }
 private JFreeChart createChart(final PieDataset dataset) {
   final JFreeChart chart =
       ChartFactory.createPieChart3D(
           "Pie Chart 3D Demo 1 ", // chart title
           dataset, // data
           true, // include legend
           true,
           false);
   final PiePlot3D plot = (PiePlot3D) chart.getPlot();
   plot.setStartAngle(290);
   plot.setDirection(Rotation.CLOCKWISE);
   plot.setForegroundAlpha(0.5f);
   plot.setNoDataMessage("No data to display");
   return chart;
 }
예제 #7
0
  private void taxPie(
      Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) {
    double taxPercent = (tax / totalValue) * 100;
    double netValuePercent = 100 - taxPercent;

    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(taxLabel, taxPercent);
    dataset.setValue(netLabel, netValuePercent);

    PiePlot3D plot = new PiePlot3D(dataset);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator());
    plot.setInsets(new Insets(0, 5, 5, 5));
    plot.setToolTipGenerator(new CustomToolTipGenerator());
    plot.setLabelGenerator(new CustomLabelGenerator());
    plot.setSectionPaint(0, new Color(pgRed));
    plot.setSectionPaint(1, new Color(pgGreen));
    plot.setForegroundAlpha(.6f);
    plot.setOutlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);

    JFreeChart chart =
        new JFreeChart("Asset Distribution", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);

    Rectangle page = rct;

    try {
      Image img =
          Image.getInstance(
              chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()), null);
      drawDiagram(img, rct, 0, 72);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
예제 #8
0
 public InputStream create3DPieChart(String title, PieDataset data, int pngwidth, int pngheight)
     throws IOException {
   JFreeChart localJFreeChart = ChartFactory.createPieChart3D(title, data, true, true, false);
   PiePlot3D localPiePlot3D = (PiePlot3D) localJFreeChart.getPlot();
   localPiePlot3D.setStartAngle(290.0D);
   localPiePlot3D.setDirection(Rotation.CLOCKWISE);
   localPiePlot3D.setForegroundAlpha(0.5F);
   localPiePlot3D.setNoDataMessage("No data to display");
   localPiePlot3D.setSectionPaint(0, new Color(152, 251, 152));
   localPiePlot3D.setSectionPaint(1, new Color(238, 221, 130));
   localPiePlot3D.setSectionPaint(2, new Color(255, 62, 150));
   localPiePlot3D.setSectionPaint(3, new Color(139, 0, 0));
   localPiePlot3D.setSectionPaint(4, new Color(181, 181, 181));
   ChartRenderingInfo info = new ChartRenderingInfo();
   BufferedImage bi =
       localJFreeChart.createBufferedImage(pngwidth, pngheight, BufferedImage.SCALE_FAST, info);
   ByteArrayOutputStream bs = new ByteArrayOutputStream();
   ImageOutputStream imOut = ImageIO.createImageOutputStream(bs);
   ImageIO.write(bi, "GIF", imOut);
   // scaledImage1ΪBufferedImage£¬jpgΪͼÏñµÄÀàÐÍ
   InputStream istream = new ByteArrayInputStream(bs.toByteArray());
   return istream;
 }
예제 #9
0
  /**
   * Creates a sample dataset for the demo.
   *
   * @return A sample dataset.
   */
  public static JFreeChart create3DPieChart(
      String title,
      java.awt.Font titleFont,
      CategoryDataset data,
      TableOrder order,
      boolean legend,
      boolean tooltips,
      boolean urls,
      PieURLGenerator urlGenerator) {

    MultiplePiePlot plot = new MultiplePiePlot(data);
    plot.setDataExtractOrder(order);

    // plot.setOutlineStroke(null);

    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);

    PiePlot3D pp = (PiePlot3D) plot.getPieChart().getPlot();
    pp.setBackgroundPaint(null);
    // pp.setInsets(new Insets(0, 5, 5, 5));

    // no outline around each piechart
    pp.setOutlineStroke(null);

    PieToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
      tooltipGenerator = new StandardPieToolTipGenerator();
    }

    if (!urls) {
      urlGenerator = null;
    }

    pp.setToolTipGenerator(tooltipGenerator);
    pp.setLabelGenerator(null);
    pp.setURLGenerator(urlGenerator);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, legend);

    return chart;
  }
예제 #10
0
  public static String getSimplePieChart(Map dataSource, String objectName, HttpSession session)
      throws Throwable {
    DefaultPieDataset dataset = new DefaultPieDataset();

    Element chartObject =
        XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName);

    String title = chartObject.getAttributeValue("title");

    int width = Integer.parseInt(chartObject.getAttributeValue("width"));
    int height = Integer.parseInt(chartObject.getAttributeValue("height"));

    Element LabelKeys = chartObject.getChild("Labels");
    Element ValueKeys = chartObject.getChild("Values");

    String valueKey = ValueKeys.getText();
    String valueType = ValueKeys.getAttributeValue("type");
    List labelKeys = LabelKeys.getChildren("Label");
    String labelKey = LabelKeys.getText();

    if (valueType.equalsIgnoreCase("number")) {
      for (int i = 0; i < dataSource.size(); i++) {
        Map rec = (Map) dataSource.get("ROW" + i);
        Number value = (Number) rec.get(valueKey);
        String label;
        if (labelKeys.isEmpty()) {
          label = DataFilter.show(rec, labelKey);
        } else {
          label = ((Element) labelKeys.get(i)).getText();
        }
        dataset.setValue(label, value);
      }
    } else {
      for (int i = 0; i < dataSource.size(); i++) {
        Map rec = (Map) dataSource.get("ROW" + i);
        double value = (Double) rec.get(valueKey);
        String label;
        if (labelKeys.isEmpty()) {
          label = DataFilter.show(rec, labelKey);
        } else {
          label = ((Element) labelKeys.get(i)).getText();
        }
        dataset.setValue(label, value);
      }
    }

    JFreeChart chart =
        ChartFactory.createPieChart3D(
            title,
            dataset,
            chartObject.getAttribute("showLegend").getBooleanValue(),
            chartObject.getAttribute("showToolTips").getBooleanValue(),
            chartObject.getAttribute("urls").getBooleanValue());

    PiePlot3D pie3dplot = (PiePlot3D) chart.getPlot();

    float alpha = 0.7F;
    if (chartObject.getAttribute("alpha") != null) {
      alpha = chartObject.getAttribute("alpha").getFloatValue();
    }
    pie3dplot.setForegroundAlpha(alpha);

    return ServletUtilities.saveChartAsPNG(chart, width, height, null, session);
  }