CategoryPlot with threshold and outliers

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sarsipius
Posts: 15
Joined: Fri Apr 10, 2009 1:23 pm

CategoryPlot with threshold and outliers

Post by sarsipius » Fri Apr 17, 2009 4:00 pm

Hi,

I try to draw a plot with categories, 2 thresholds and some outliers

This picture shows what I can do right now:

Image

And here is my code:

Code: Select all

LineAndShapeRenderer renderer0 = new LineAndShapeRenderer();
renderer0.setBaseLinesVisible(true);
renderer0.setBaseShapesVisible(false);
renderer0.setBaseSeriesVisibleInLegend(false);
renderer0.setBaseToolTipGenerator(this);
renderer0.setSeriesPaint(0,new Color(0,255,0,60));
renderer0.setSeriesPaint(1,new Color(0,255,0,60));
plot.setRenderer(0,renderer0);
plot.setDataset(0,getThreshold());
		
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseLinesVisible(false);
renderer1.setBaseSeriesVisibleInLegend(false);
renderer1.setBaseToolTipGenerator(this);
renderer1.setSeriesPaint(0,Color.BLUE);
renderer1.setSeriesShape(0,CustomShape.getSquare());
plot.setRenderer(1,renderer1);
plot.setDataset(1,getBaseline());

LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
renderer2.setBaseLinesVisible(false);
renderer2.setBaseSeriesVisibleInLegend(false);
renderer2.setBaseToolTipGenerator(this);
for(int i=0;i<15;i++) {
	renderer2.setSeriesPaint(i,Color.GREEN);
	renderer2.setSeriesShape(i,CustomShape.getDiamond());
}
plot.setRenderer(2,renderer2);
plot.setDataset(2,getData());
But I want to go further :)

1) For the moment I use 3 LineAndShapeRenderer (the blue squares, the green diamonds and the green lines for the threshold) and the methods setSeriesPaint and setSeriesShape

How could I use a more generic method in order to specify the color and the shape for one renderer and not for each serie?
I try setBasePaint and setBaseShape but it doesn't work...

2) How could I paint the outliers in red?
I have read that I could override the getItemPaint method but I don't understand how to do that

Thanks for your help

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: CategoryPlot with threshold and outliers

Post by RichardWest » Fri Apr 17, 2009 7:31 pm

sarsipius wrote:I have read that I could override the getItemPaint method but I don't understand how to do that
There are two ways: either create a new class that extends LineAndShapeRenderer or create an anonymous class on the fly.

Code: Select all

public class MyLineAndShapeRenderer
    extends LineAndShapeRenderer
{
    public MyLineAndShapeRenderer(...) {
        super(...);
        // other class specific stuff
    }

    public java.awt.Paint getItemPaint(int row, int column) {
        // your custom code
    }

   // repeat for all methods you want to overrride
}

Code: Select all

LineAndShapeRenderer renderer = new LineAndShapeRenderer(...) {
    public java.awt.Paint getItemPaint(int row, int column) {
        // your custom code
    }

    // repeat for all methods you want to overrride
};
The methods you will probably wnat to override are getItemPaint, getItemShape, and getItemOutlinePaint. All three of these methods are provided with the intent that they be overriden for highly cutomized renderers. If you do not override these methods, they will simply pass controll to the corresponding lookup* methods which return a default value based on the series.

You can use an IntervalMarker to draw the green strip in the background.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

sarsipius
Posts: 15
Joined: Fri Apr 10, 2009 1:23 pm

Re: CategoryPlot with threshold and outliers

Post by sarsipius » Mon Apr 20, 2009 9:24 am

I have read that I could override the LineAndShapeRenderer class but I still don't understand how to use it

Should I create a new serie "Outliers" and set the custom LineAndShapeRenderer?
Or is it possible to apply the custom renderer to an individual item?

And for my first question, could I use a generic method to apply shape and color for a dataset and not for each serie of a dataset?

sarsipius
Posts: 15
Joined: Fri Apr 10, 2009 1:23 pm

Re: CategoryPlot with threshold and outliers

Post by sarsipius » Mon Apr 20, 2009 11:35 am

ok sorry I was not awake this morning ;)

it works perfectly now
Thanks!

Locked