user1130642
user1130642

Reputation: 13

How to switch between 2 TimeSeriesCollection in the same JFreeChart

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?

Upvotes: 1

Views: 308

Answers (1)

trashgod
trashgod

Reputation: 205795

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.

Upvotes: 1

Related Questions