示例#1
0
  /**
   * Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i>
   * event if/when the series is deleted from the chart by the user. Returns the series attributes.
   */
  public SeriesAttributes addSeries(Collection objs, String name, SeriesChangeListener stopper) {
    int i = getSeriesCount();

    // need to have added the dataset BEFORE calling this since it'll try to change the name of the
    // series
    PieChartSeriesAttributes csa = buildNewAttributes(name, stopper);

    // set information
    csa.setElements(new ArrayList(objs));

    seriesAttributes.add(csa);

    revalidate(); // display the new series panel
    update();

    // won't update properly unless I force it here by letting all the existing scheduled events to
    // go through.  Dumb design.  :-(
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            update();
          }
        });

    return csa;
  }
示例#2
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);
  }
示例#3
0
  public void updateSeries(int index, Object[] objs) {
    if (index < 0) // this happens when we're a dead chart but the inspector doesn't know
    return;

    if (index
        >= getNumSeriesAttributes()) // this can happen when we close a window if we use the
                                     // Histogram in a display
    return;

    PieChartSeriesAttributes hsa = (PieChartSeriesAttributes) (getSeriesAttribute(index));
    hsa.setElements((Object[]) (objs.clone()));
  }
示例#4
0
  public void updateSeries(int index, double[] amounts, String[] labels) {
    if (index < 0) // this happens when we're a dead chart but the inspector doesn't know
    return;

    if (index
        >= getNumSeriesAttributes()) // this can happen when we close a window if we use the
                                     // Histogram in a display
    return;

    PieChartSeriesAttributes hsa = (PieChartSeriesAttributes) (getSeriesAttribute(index));
    hsa.setValues((double[]) (amounts.clone()));
    hsa.setLabels((String[]) (labels.clone()));
  }