dynamic addition and removal of timeseries overlays

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kab
Posts: 3
Joined: Wed Feb 23, 2005 1:58 am
Location: Cambridge, MA, USA

dynamic addition and removal of timeseries overlays

Post by kab » Wed Feb 23, 2005 2:25 am

Adapting the techniques from OverlaidXYPlotDemo2, I have a simple
program which creates and displays a time series plot, and then
dynamically -- in response to the user pressing a button -- adds an
overlaid time series. All the overlays share the same domain and range
axes as the main plot in this example. The overlay code is basically this:

Code: Select all

TimeSeriesCollection ds = // get the additional series...
XYPlot plot = _mainChart.getXYPlot();
int k = plot.getDatasetCount();
plot.setDataset(k, ds);
plot.setRenderer(k, new StandardXYItemRenderer());
plot.mapDatasetToRangeAxis(k, 0);
This works fine to add an additional time series.

Is there a method whereby I can delete the overlaid series plot
while still retaining the original main plot (and hopefully other
independently overlaid graphs)?? I get the feeling that things are
handled as panes (but I haven't drilled down far enough in the code
yet to really have understanding), so is there a way to "erase"
pane #k above??

Or is there a significantly different approach to achieve the same goal:
Create a basic plot, and then dynamically add and delete overlays in
response to user button presses??

Many thanks,

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 Feb 23, 2005 10:22 am

You've added an additional dataset and renderer with index 'k'. By default, these will map to domain axis 0 and range axis 0, so you could delete the line that adds that mapping explicitly. When you want the additional data to disappear from the chart, you can set both the dataset and renderer (with index 'k') to null.

Alternatively, if you are always displaying/hiding individual time series, you can do this with a single dataset and renderer and set the flags that control the visibility of each series in the renderer - see the HideSeriesDemo.java file in the demos included with the JFreeChart Developer Guide.
David Gilbert
JFreeChart Project Leader

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

Locked