1

In my program I need to display a JFreeChart. I'm adding, over time, series to that JFreeChart. I'm having a tree who allows me to switch between different item and displaying them in the chart. What i do is that I update the TimeSeriesCollection. (Update or reset completely with new data)

But I need in a specific case to add data to one of my item, thus displaying the chart with the new data, and at the same time, the user might change item and the program still needs to update my 1st item while displaying the second.

Which mean i have a graph of "Item1" to which I'm adding data over time, and while doing that, i want to be able to switch to an "Item2" and displaying that item in the graph (while still adding my data to "item1")

I tough about using an other TimeSeriesCollections to wich i could put the new data while displaying the first TimeSeriesCollections. But i can't seem to find a way to switch between 2 TimeSeriesCollection.. like a myJFreeChart.setTimeSeriesCollection(TimesSeriesCollections tsc)

Any ideas?

Chillie
  • 1,030
  • 10
  • 28

1 Answers1

1

As shown here, create your chart with a TimeSeriesCollection. As long as you have distinct TimeSeries instances, you can use removeSeries() and addSeries() to swap them as required. The ChangeListener will be adjusted accordingly. You can still add data to either series.

If you're still having problems, edit your question to include an sscce.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks for your answer, I actually found the solution alone, i was not doing the right thing. I was trying to update my chart, and my database at the same time and trying to refresh everything on the chart. But I just needed to update my database and refresh only the item that's being displayed, and not all of them.. So it's just my fault.. thanks again. – user1130642 Jan 09 '12 at 14:51