Different colours on a line between 2 data points

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
jmbalas
Posts: 1
Joined: Tue Sep 02, 2008 2:10 pm

Post by jmbalas » Fri Sep 05, 2008 7:18 pm

Hello,

I'm trying to adapt the code shown previously which overrides SetRenderer for a LineAndShapeRender. Any suggestions on how to apply to an XYBoxAndWhiskerRenderer? I'm able to get it to change the color for the entire series, but not specific individual items.

Thanks for the help.
John

zartc
Posts: 1
Joined: Wed May 27, 2009 10:16 am

Re:

Post by zartc » Thu May 28, 2009 11:42 am

jfreeuser2006 wrote:you could do something like this:

Code: Select all

plot.setRenderer(new LineAndShapeRenderer() {
    public Paint getItemPaint(int row, int item) {
        double temp = plot.getDataset().getValue(row, item).doubleValue();

        if (temp >= limit) {
            return Color.RED;
        }

        return Color.BLUE;
    }

    public Shape getItemShape(int row, int item) {
        return ShapeUtilities.createDiamond(2.0f);
    }
});
Is it possible to elaborate on this example to create and return a GradiantPaint ?
Right now I have tried this:

Code: Select all

public class MyRenderer extends XYLineAndShapeRenderer {
	private Color[] myColors = new Color[] { 
		new Color(0xFF0000), new Color(0xFFBF00), new Color(0x00AA54), new Color(0x3F00BF) };

	@Override
	public Paint getItemPaint(final int row, final int column) {
		int x1 = 0, x2 = 0;	// How to compute good values for x and y ???
		int y1 = 10, y2 = 10;
		return new GradientPaint(x1, y1, getMyColor(column), x2, y2, getMyColor(column+1), false);
	}
		
	public Color getMyColor(final int i) {
		return myColors[i % myColors.length];
	}
}
unfortunately this doesn't work because I'm unable to calculate good values for x1, x2, y1, y2.

ZC

Locked