Examples of PiePlot


Examples of org.jfree.chart.plot.PiePlot

    public static JFreeChart createPieChart(String title, PieDataset dataset,
            PieDataset previousDataset, int percentDiffForMaxScale,
            boolean greenForIncrease, boolean legend, boolean tooltips,
            Locale locale, boolean subTitle, boolean showDifference) {

        PiePlot plot = new PiePlot(dataset);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
        plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

        if (tooltips) {
            plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
        }

        List keys = dataset.getKeys();
        DefaultPieDataset series = null;
        if (showDifference) {
            series = new DefaultPieDataset();
        }

        double colorPerPercent = 255.0 / percentDiffForMaxScale;
        for (Iterator it = keys.iterator(); it.hasNext();) {
            Comparable key = (Comparable) it.next();
            Number newValue = dataset.getValue(key);
            Number oldValue = previousDataset.getValue(key);

            if (oldValue == null) {
                if (greenForIncrease) {
                    plot.setSectionPaint(key, Color.green);
                }
                else {
                    plot.setSectionPaint(key, Color.red);
                }
                if (showDifference) {
                    series.setValue(key + " (+100%)", newValue);
                }
            }
            else {
                double percentChange = (newValue.doubleValue()
                        / oldValue.doubleValue() - 1.0) * 100.0;
                double shade
                    = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
                if (greenForIncrease
                        && newValue.doubleValue() > oldValue.doubleValue()
                        || !greenForIncrease && newValue.doubleValue()
                        < oldValue.doubleValue()) {
                    plot.setSectionPaint(key, new Color(0, (int) shade, 0));
                }
                else {
                    plot.setSectionPaint(key, new Color((int) shade, 0, 0));
                }
                if (showDifference) {
                    series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
                            + NumberFormat.getPercentInstance().format(
                            percentChange / 100.0) + ")", newValue);
                }
            }
        }

        if (showDifference) {
            plot.setDataset(series);
        }

        JFreeChart chart =  new JFreeChart(title,
                JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

                                            boolean tooltips,
                                            boolean urls,
                                            boolean subTitle,
                                            boolean showDifference) {

        PiePlot plot = new PiePlot(dataset);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
        plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));

        if (tooltips) {
            plot.setToolTipGenerator(new StandardPieToolTipGenerator());
        }
        if (urls) {
            plot.setURLGenerator(new StandardPieURLGenerator());
        }

        List keys = dataset.getKeys();
        DefaultPieDataset series = null;
        if (showDifference) {
            series = new DefaultPieDataset();
        }

        double colorPerPercent = 255.0 / percentDiffForMaxScale;
        for (Iterator it = keys.iterator(); it.hasNext();) {
            Comparable key = (Comparable) it.next();
            Number newValue = dataset.getValue(key);
            Number oldValue = previousDataset.getValue(key);

            if (oldValue == null) {
                if (greenForIncrease) {
                    plot.setSectionPaint(key, Color.green);
                }
                else {
                    plot.setSectionPaint(key, Color.red);
                }
                if (showDifference) {
                    series.setValue(key + " (+100%)", newValue);
                }
            }
            else {
                double percentChange = (newValue.doubleValue()
                        / oldValue.doubleValue() - 1.0) * 100.0;
                double shade
                    = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255
                    : Math.abs(percentChange) * colorPerPercent);
                if (greenForIncrease
                        && newValue.doubleValue() > oldValue.doubleValue()
                        || !greenForIncrease && newValue.doubleValue()
                        < oldValue.doubleValue()) {
                    plot.setSectionPaint(key, new Color(0, (int) shade, 0));
                }
                else {
                    plot.setSectionPaint(key, new Color((int) shade, 0, 0));
                }
                if (showDifference) {
                    series.setValue(key + " (" + (percentChange >= 0 ? "+" : "")
                            + NumberFormat.getPercentInstance().format(
                            percentChange / 100.0) + ")", newValue);
                }
            }
        }

        if (showDifference) {
            plot.setDataset(series);
        }

        JFreeChart chart =  new JFreeChart(title,
                JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        plot.setOutlineStroke(null);

        if (tooltips) {
            PieToolTipGenerator tooltipGenerator
                = new StandardPieToolTipGenerator();
            PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
            pp.setToolTipGenerator(tooltipGenerator);
        }

        if (urls) {
            PieURLGenerator urlGenerator = new StandardPieURLGenerator();
            PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
            pp.setURLGenerator(urlGenerator);
        }

        JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
                plot, legend);
        currentTheme.apply(chart);
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        plot.setPieChart(pieChart);

        if (tooltips) {
            PieToolTipGenerator tooltipGenerator
                = new StandardPieToolTipGenerator();
            PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
            pp.setToolTipGenerator(tooltipGenerator);
        }

        if (urls) {
            PieURLGenerator urlGenerator = new StandardPieURLGenerator();
            PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
            pp.setURLGenerator(urlGenerator);
        }

        JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
                plot, legend);
        currentTheme.apply(chart);
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        if (plot instanceof Zoomable) {
            Zoomable zoomable = (Zoomable) plot;
            handleZoomable(zoomable, e);
        }
        else if (plot instanceof PiePlot) {
            PiePlot pp = (PiePlot) plot;
            pp.handleMouseWheelRotation(e.getWheelRotation());
        }
    }
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        } else {
            chart = ChartFactory.createPieChart
                (null, pieData, true, false, false);
        }

        PiePlot plot = (PiePlot) chart.getPlot();
        if (parameters.get("skipWedgeLabels") != null)
            plot.setSectionLabelType(PiePlot.NO_LABELS);
        else if (parameters.get("wedgeLabelFontSize") != null) try {
            float fontSize =
                Float.parseFloat(getParameter("wedgeLabelFontSize"));
            plot.setSeriesLabelFont
                (plot.getSeriesLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {}
        if (parameters.get("ellipse") != null)
            plot.setCircular(true);
        else
            plot.setCircular(false);

        String interiorGap = getParameter("interiorGap");
        if (interiorGap != null) try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {}
        String interiorSpacing = getParameter("interiorSpacing");
        if (interiorSpacing != null) try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {}

        return chart;
    }
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        } else {
            chart = ChartFactory.createPieChart
                (null, pieData, true, true, false);
        }

        PiePlot plot = (PiePlot) chart.getPlot();
        if (parameters.get("skipItemLabels") != null
                || parameters.get("skipWedgeLabels") != null)
            plot.setLabelGenerator(null);
        else if (parameters.get("wedgeLabelFontSize") != null) try {
            float fontSize =
                Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {}
        if (parameters.get("ellipse") != null)
            plot.setCircular(true);
        else
            plot.setCircular(false);

        Object colorScheme = parameters.get("colorScheme");
        if ("byPhase".equals(colorScheme))
            maybeConfigurePhaseColors(plot, pieData);
        else if ("consistent".equals(colorScheme))
            // since 2.0.9
            configureConsistentColors(plot, pieData);

        String interiorGap = (String) parameters.get("interiorGap");
        if (interiorGap != null) try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {}
        String interiorSpacing = (String) parameters.get("interiorSpacing");
        if (interiorSpacing != null) try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {}
       
        if (!parameters.containsKey("showZeroValues")) {
            plot.setIgnoreZeroValues(true);
            plot.setIgnoreNullValues(true);
        }

        return chart;
    }
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

    public void processChart (Object chart, Map params) {
    Plot plot = ((JFreeChart) chart).getPlot();

    if (plot instanceof PiePlot) {
      PiePlot piePlot = (PiePlot) plot;

      double interiorGap = piePlot.getInteriorGap();
      double labelGap = piePlot.getLabelGap();
      double startAngle = piePlot.getStartAngle();
      boolean simpleLabels = piePlot.getSimpleLabels();
      boolean showSectionLabels = piePlot.getLabelGenerator() != null;

      String str = (String) params.get("interiorGap");
      if (str != null) {
        try {
          interiorGap = Double.parseDouble(str);
        } catch (NumberFormatException nfex) { }
      }

      str = (String) params.get("labelGap");
      if (str != null) {
        try {
          labelGap = Double.parseDouble(str);
        } catch (NumberFormatException nfex) { }
      }

      str = (String) params.get("startAngle");
      if (str != null) {
        try {
          startAngle = Double.parseDouble(str);
        } catch (NumberFormatException nfex) { }
      }

      str = (String) params.get("simpleLabels");
      if (str != null)
        simpleLabels = "true".equals(str);

      str = (String) params.get("showSectionLabels");
      if (str != null)
        showSectionLabels = "true".equals(str);

      piePlot.setSimpleLabels(simpleLabels);
      piePlot.setInteriorGap(interiorGap);
      piePlot.setLabelGap(labelGap);
      piePlot.setStartAngle(startAngle);
      if (! showSectionLabels)
        piePlot.setLabelGenerator(null);

      // The following section deals with whether individual pie sections are exploded or not.
      // Although PiePlot3D extends PiePlot, it does not support exploded sections.
      if (! (plot instanceof PiePlot3D)) {
        PieDataset ds = piePlot.getDataset();

        for (Iterator paramIter=params.entrySet().iterator(); paramIter.hasNext(); ) {
          Map.Entry entry = (Map.Entry) paramIter.next();
          String paramKey = (String) entry.getKey();
          if (paramKey.startsWith("explode_")) {
            double explodePercent = Double.valueOf(paramKey.substring(8)).doubleValue();
            String paramValue = (String) entry.getValue();

            for (Iterator keyIter=ds.getKeys().iterator(); keyIter.hasNext(); ) {
              Comparable key = (Comparable) keyIter.next();
              if (key.equals(paramValue)) {
                piePlot.setExplodePercent(key, explodePercent);
              }
            }
          }
        }
      }
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

            dataset, false, // legend?
            true, // tooltips?
            false // URLs?
            );
        chart.addSubtitle(new TextTitle("http://en.wikipedia.org/wiki/List_of_countries_by_military_expenditures"));
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        plot.setBackgroundPaint(Color.WHITE);
        plot.setOutlinePaint(null);

        RadialGradientPaint p = new RadialGradientPaint(
                new Point2D.Float(0, 0),
                100,
                new float[] {0.1f, 0.4f, 1},
                new Color[] {Color.BLUE, Color.red, Color.yellow},
                CycleMethod.REFLECT);
        plot.setSectionPaint("United States", p);

        return chart;

    }
View Full Code Here

Examples of org.jfree.chart.plot.PiePlot

        JFreeChart chart = null;
        final boolean drilldown = true;

        // create the chart...
        if (drilldown) {
            final PiePlot plot = new PiePlot(pieDataSet);

            Color[] colors = {new Color(100, 230, 40), new Color(210, 35, 35), new Color(230, 210, 40), new Color(100, 90, 40)};
            PieRenderer renderer = new PieRenderer(colors);
            renderer.setColor(plot, (DefaultPieDataset) pieDataSet);

            plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp"));
            plot.setLabelGenerator(new TestSectiontLabelPieGenerator());
            chart = new JFreeChart("Test summary", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        } else {
            chart = ChartFactory.createPieChart(
                    "Test summary", // chart title
                    pieDataSet, // data
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.