示例#1
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;
 }
示例#2
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;
  }
  @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;
 }
示例#6
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;
 }
示例#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 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);
  }