Deviation renderer - drawing min/max as lines

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
I82Much
Posts: 5
Joined: Fri Jun 26, 2009 6:55 pm

Deviation renderer - drawing min/max as lines

Post by I82Much » Tue Jul 07, 2009 6:08 pm

Hello all,

I am attempting to draw dashed lines along the top and bottom of a deviation renderer output. Right now the best idea I have to do that is to get the YIntervalSeries that backs the deviation renderer and make new XYSeries, one for the min, and one for the max, and then draw these series with a new renderer (StandardXYRenderer, for instance). This seems wasteful to me, as then the high/low data is duplicated.


For instance, here is the code I'm using to extract the mins and then draw the mins as a new series:

Code: Select all

private static XYDataset getMinFromInterval(YIntervalSeriesCollection dataset) {
        XYSeriesCollection lowDataset = new XYSeriesCollection();

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            YIntervalSeries series = dataset.getSeries(i);
            XYSeries lowVals = new XYSeries(series.getKey());
            for (int j = 0; j < series.getItemCount(); j++) {
                lowVals.add(series.getX(j), series.getYLowValue(j));
            }
            lowDataset.addSeries(lowVals);
        }

        return lowDataset;
    }
I then draw these as follows

Code: Select all

plot.setDataset(1, getMinFromInterval((YIntervalSeriesCollection) dataset));
        plot.setRenderer(1, new StandardXYItemRenderer());
Where plot is created as in the DeviationRendererDemo2 code.

Thanks for any help you can provide,

Nick

(The other thought that occurs to me is that I could extend the DeviationRenderer class, but that might be going a bit far)

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

Re: Deviation renderer - drawing min/max as lines

Post by david.gilbert » Tue Jul 07, 2009 8:22 pm

I82Much wrote:The other thought that occurs to me is that I could extend the DeviationRenderer class, but that might be going a bit far
I think that would be the right approach. All the data is there, and all you are looking for is a change in (or rather an addition to) the rendering...so modifying the renderer makes the most sense.

I think you'd need to change the block in the drawItem() method that starts with:

Code: Select all

if (isLinePass(pass)) {
...and get it to store an additional two lines in the State object, one for the lower bound and one for the upper bound - then at the end of each series, render the lines. It should work, although it isn't a completely straightforward change otherwise I'd do it myself right now.
David Gilbert
JFreeChart Project Leader

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

Locked