Example #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);
  }