Esempio n. 1
0
  protected void update() {
    // We have to rebuild the dataset from scratch (deleting and replacing it) because JFreeChart's
    // piechart facility doesn't have a way to move series.  Just like the histogram system: stupid
    // stupid stupid.

    SeriesAttributes[] sa = getSeriesAttributes();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < sa.length; i++)
      if (sa[i].isPlotVisible()) {
        PieChartSeriesAttributes attributes = (PieChartSeriesAttributes) (sa[i]);

        Object[] elements = attributes.getElements();
        double[] values = null;
        String[] labels = null;
        if (elements != null) {
          HashMap map = convertIntoAmountsAndLabels(elements);
          labels = revisedLabels(map);
          values = amounts(map, labels);
        } else {
          values = attributes.getValues();
          labels = attributes.getLabels();
        }

        UniqueString seriesName = new UniqueString(attributes.getSeriesName());

        for (int j = 0; j < values.length; j++)
          dataset.addValue(values[j], labels[j], seriesName); // ugh
      }

    setSeriesDataset(dataset);
  }
Esempio n. 2
0
  protected void buildChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    chart =
        ChartFactory.createMultiplePieChart(
            "Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN, false, true, false);
    chart.setAntiAlias(true);
    // chartPanel = new ScrollableChartPanel(chart, true);
    chartPanel = buildChartPanel(chart);
    // chartHolder.getViewport().setView(chartPanel);
    setChartPanel(chartPanel);

    JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart();
    PiePlot base = (PiePlot) (baseChart.getPlot());
    base.setIgnoreZeroValues(true);
    base.setLabelOutlinePaint(java.awt.Color.WHITE);
    base.setLabelShadowPaint(java.awt.Color.WHITE);
    base.setMaximumLabelWidth(
        0.25); // allow bigger labels by a bit (this will make the chart smaller)
    base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width
    base.setLabelBackgroundPaint(java.awt.Color.WHITE);
    base.setOutlinePaint(null);
    base.setBackgroundPaint(null);
    base.setShadowPaint(null);
    base.setSimpleLabels(false); // I think they're false anyway

    // change the look of the series title to be smaller
    StandardChartTheme theme = new StandardChartTheme("Hi");
    TextTitle title = new TextTitle("Whatever", theme.getLargeFont());
    title.setPaint(theme.getAxisLabelPaint());
    title.setPosition(RectangleEdge.BOTTOM);
    baseChart.setTitle(title);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
  }