Renaming TimeSeries Dynamically

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
JDJ
Posts: 7
Joined: Fri Aug 11, 2006 4:35 pm

Renaming TimeSeries Dynamically

Post by JDJ » Mon Aug 21, 2006 9:14 pm

Here's a question:

Once you create a TimeSeries with a name, can you change the name with a dynamic event such as a button click.

Or, do you have to redraw the whole graph?

JDJ
Posts: 7
Joined: Fri Aug 11, 2006 4:35 pm

Post by JDJ » Wed Aug 23, 2006 4:43 pm

I got this answer from SeanMcCrohan in another post:

The way to rename a TimeSeries is
1. remove all series from the dataset
2. add new TimeSeries with new name

The code would look something like this (inside an event such as getActionCommand). In this example, you can re-draw the graph with new name and datapoint.

--------------------------------------
this.dataset.removeAllSeries();

this.series = new TimeSeries("New Name", Millisecond.class);
this.dataset.addSeries(this.series);

this.series.add(new Millisecond(), newValue);
--------------------------------------

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Aug 23, 2006 5:58 pm

You should be able to just call the setKey() method in the TimeSeries class and the chart should update automatically.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked