5

Let's say I've generated a chart with the following code:

private ChartPanel createChart(){
        XYSeries series1 = new XYSeries("First");
        XYSeries series2 = new XYSeries("Second");
        XYSeries series3 = new XYSeries("Third");

        series1.add(0.0, 5.5);
        series1.add(5, 10);
        series1.add(10, 5.5);

        series2.add(0.0, 2);
        series2.add(5, 2);
        series2.add(10, 7);

        series3.add(0.0, 10);
        series3.add(5, 5);
        series3.add(10, 6);

        XYSeriesCollection dataset = new XYSeriesCollection();

        dataset.addSeries(series1);
        dataset.addSeries(series2);
        dataset.addSeries(series3);

        JFreeChart chart = ChartFactory.createXYLineChart("line chart example",
                "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        return chartPanel;
    }

Now I would like to modify a value previously inserted in an XYSeries without build another chart (no other call to createXYLineChart), and make the chart automatically updated.

How do this?

Heisenbug
  • 38,762
  • 28
  • 132
  • 190

1 Answers1

1

Just look at the api.

There are many different methods, depending if you know the index of the element in the series, or if you know the x-value, but want to change the y-value. I assume the chart will be redrawn since all the methods throw a SeriesChangeEvent.

toto2
  • 5,306
  • 21
  • 24
  • could you tell me at least one method name? – Heisenbug Aug 23 '11 at 16:51
  • `update`, `updateByIndex`, `addOrUpdate`. Actually, it looks like that if you want to change the x-coordinate, you'll have to erase the point first with `remove`; `remove` can take the x-value or the index of the point in the series. – toto2 Aug 23 '11 at 17:30
  • no..actually i would like to change only the y cordinate. I think updateByIndex will work.thanks. – Heisenbug Aug 23 '11 at 17:38