Package org.jfree.chart.plot

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


        } 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

        } 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

    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

            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

        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

            }
            if (event.getSortOrderPieChartByValue() != null) {
                dataset.sortByKeys(event.getSortOrderPieChartByValue());
            }
           
            PiePlot plot = (PiePlot) chart.getPlot();
           
            if (event.isShowPercentages()) {
                plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}"));
            } else {
                plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1}"));
            }
        }

        for (int i = 0; i < event.getPieData().length; i++) {
            dataset.setValue(event.getPieDataNames()[i], event.getPieData()[i]);
        }
       
        // Exploded segments.
        PiePlot plot = (PiePlot) chart.getPlot();
       
        for (String key : event.getExplodedSegmentsPie().keySet()) {
            plot.setExplodePercent(key, event.getExplodedSegmentsPie().get(key));
        }
       
        // Segment paints.
        for (String key : event.getPaintSegments().keySet()) {
            plot.setSectionPaint(key, event.getPaintSegments().get(key));
        }
  }
View Full Code Here

            dataset,             // dataset
            true,                // include legend
            true,
            false
        );
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setNoDataMessage("No data available");
        plot.setExplodePercent("Three", 0.30);
        plot.setExplodePercent("One", 0.30);
        plot.setExplodePercent("Five", 0.10);
        return chart;
    }
View Full Code Here

        }
        dataset.setValue(name, Double.parseDouble(data[i].toString()));
      }

      chart = ChartFactory.createPieChart(title, dataset, true, false, false);
      PiePlot plot = (PiePlot) chart.getPlot();
      // 设置显示格式, {0}表示名称, {1}表示值, {2}表示百分比值
      if (labelFormat != null) {
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
            labelFormat, NumberFormat.getNumberInstance(), new DecimalFormat(
                "0.0%")));
      }
      plot.setLabelFont(tickLabelFont);
      break;
    }
    case VBAR:
    case HBAR:
    case LINE:
    case SPIDER: {
      // 设置填充的数据集
      DefaultCategoryDataset dataset = new DefaultCategoryDataset();

      int step = 1 + (itemNames == null ? 1 : 0)
          + (groupNames != null && groupNames[0].length() == 0 ? 1 : 0);
      for (int i = 0; i < size; i++) {
        String name;
        if (itemNames != null) {
          name = itemNames[groupNames != null && groupNames[0].length() > 0 ? (i / step)
              / groupNames.length
              : i * itemNames.length / size];
        } else {
          name = data[i].toString();
          i++;
        }
        String category;
        if (groupNames != null) {
          if (groupNames[0].length() == 0) {
            category = data[i].toString();
            i++;
          } else {
            category = groupNames[((i / step) % groupNames.length)];
          }
        } else {
          category = "";
        }
        dataset
            .addValue(Double.parseDouble(data[i].toString()), category, name);
      }

      if (type == SPIDER) {
        AdvancedSpiderWebPlot plot = new AdvancedSpiderWebPlot(dataset);
        chart = new JFreeChart(title, titleFont, plot, groupNames != null);
        if (labelFormat != null) {
          plot.setLabelGenerator(new StandardCategoryItemLabelGenerator(
              labelFormat, NumberFormat.getNumberInstance(), new DecimalFormat(
                  "0.0%")));
        }
        plot.setLabelFont(labelFont);
        if (keys != null) {
          plot.setMaxValue(Double.parseDouble(keys[0]));
        }
      } else {
        if (type == LINE) {
          chart = ChartFactory.createLineChart(title, keys[0], keys[1],
              dataset, PlotOrientation.VERTICAL, groupNames != null, false,
              false);
        } else {
          chart = ChartFactory.createBarChart(title, keys[0], keys[1], dataset,
              type == VBAR ? PlotOrientation.VERTICAL
                  : PlotOrientation.HORIZONTAL, groupNames != null, false,
              false);
        }
        CategoryPlot plot = chart.getCategoryPlot();
        // 设置显示值的数字
        AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) plot
            .getRenderer();
        if (labelFormat != null) {
          renderer.setBaseItemLabelFont(labelFont);
          renderer.setBaseItemLabelsVisible(true);
          renderer
              .setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        }
        if (type == LINE) {
          // 线条模式设置显示节点图形
          ((LineAndShapeRenderer) renderer).setBaseShapesVisible(true);
        }

        // 设置数值轴的信息
        {
          NumberAxis axis = (NumberAxis) plot.getRangeAxis();
          axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
          axis.setUpperMargin(0.12D);
          axis.setLabelFont(labelFont);
          axis.setTickLabelFont(tickLabelFont);
        }

        // 设置分类/标题轴的信息
        {
          CategoryAxis axis = plot.getDomainAxis();
          axis.setLabelFont(labelFont);
          axis.setTickLabelFont(tickLabelFont);
        }
      }
      break;
View Full Code Here

        chart.setBackgroundPaint(Color.white);
        chart.setBorderVisible(false);
        chart.setBorderPaint(null);


        PiePlot plot = (PiePlot)chart.getPlot();
        plot.setSectionOutlinesVisible(false);
        plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
        plot.setNoDataMessage("No data available");
        plot.setCircular(true);
        plot.setLabelGap(0.02);
        plot.setOutlinePaint(null);
        plot.setLabelLinksVisible(false);

        plot.setLabelGenerator(null);

        plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));


        plot.setStartAngle(270);
        plot.setDirection(Rotation.ANTICLOCKWISE);
        plot.setForegroundAlpha(0.60f);
        plot.setInteriorGap(0.33);

        return chart;
    }
View Full Code Here

TOP

Related Classes of org.jfree.chart.plot.PiePlot

Copyright © 2018 www.massapicom. 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.