I am not a newbie to JFreeChart, but I'm no expert either. I spent more than half a day messing around with a multiple-axis time series graph... the main part was quick and easy, it was setting the colours that took all the time.
I am graphing varying numbers of traces against a varying number of axes e.g. a couple of voltage traces, a pressure trace etc. I want the axes/ticks/labels to be the same colour as the trace.
The crux of the problem was this: JFreeChart is clever and if there is only one of something, it will use that as the default for everything. The key then is to ensure there is one object for each Y axis in particular a DataSeriesCollection and an XYItemRenderer. This is probably obvious to experienced users but I have noticed several posts on this theme so I thought I'd write from my experience.
Here is the process I have now:
for each measurement type ( voltage etc. )
create a range axis with the required label, lower/upper bound; set the axis, tick and label colour using the setXxxPaint methods
create a new empty SeriesCollection
create a new renderer and set the colour on that using setPaint
if the chart has not been initialised
create an xAxis
create a plot using the axes, [empty] series collection and renderer
create a new chart using the plot
( if using the ChartPanel ) set the chart on the panel
else
get the plot from the chart
use setRangeAxis to add the new axis at a new index
set the series collection at the new index
set the renderer at the new index
finally map the series collection to the axis ( using the same new index number for both ) using mapDataSetToRangeAxis
Then, to add data for a series ( given the axis index ):
create a new series and add all of the data points - the index for this series needs to be from the series collection i.e. use plot.getDataset(axisIndex).getSeriesCount() to find out how many are already in the series ( not plot.getSeriesCount() )
add the series to the collection
If anyone would like to see my code I'm happy to share it.
Notes on setSeriesPaint, getSeriesCount: setting trace color
-
- Posts: 13
- Joined: Mon May 08, 2006 1:27 pm