Alpha-Transparency for Legend

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
GoodVibes

Alpha-Transparency for Legend

Post by GoodVibes » Wed Jul 07, 2004 8:56 am

hi there,

i had to set an alpha transparency for an area chart because of stacked series.
but the legend still have its own colors without an alpha value.

so how to change the alpha value of the legend to get close to the color of the charts.

could you please give me the piece of code.

Thank you
regards, Charles

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 Jul 07, 2004 5:20 pm

This is something that needs fixing. I don't know a good workaround - maybe it is possible to specify the series colors using the constructor in the Color class that takes an alpha value? (I haven't tried this, but it might work)
David Gilbert
JFreeChart Project Leader

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

GoodVibes

Post by GoodVibes » Thu Jul 08, 2004 8:43 am

Ok !

well i ll try then ...

thanks.

regards, Charles

GoodVibes

Post by GoodVibes » Thu Jul 08, 2004 10:15 am

Code: Select all

final CategoryItemRenderer renderer = plot.getRenderer(); 
    	renderer.setSeriesPaint(0, new Color(0,0,255,80)); 
    	renderer.setSeriesPaint(1, new Color(255,0,0,80)); 
it works !
this is an exemple for handling 2 series.

but still on the chart we have a new color wich is the addition of the 2 where is stacked ... :(

life isnt so easy lol

SomeOtherUser
Posts: 13
Joined: Thu Apr 06, 2006 7:55 pm

Post by SomeOtherUser » Wed Feb 14, 2007 5:01 pm

but still on the chart we have a new color wich is the addition of the 2 where is stacked ... Sad
I noticed the same thing. When using an alpha value on a stacked area chart, an overlapping of areas is shown. This occurs when a series not on the baseline has a zero value at one data point and a non-zero value at the next (or vice versa).

Is this a bug or intended rendering? Is there a way to prevent the overlap?

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 14, 2007 5:27 pm

SomeOtherUser wrote:Is this a bug or intended rendering? Is there a way to prevent the overlap?
There is a bug in the stacked area renderers that I've been working on. Maybe that's what you've run into...if you post a small self-contained demo that reproduces the problem, I'll be able to confirm it.
David Gilbert
JFreeChart Project Leader

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

SomeOtherUser
Posts: 13
Joined: Thu Apr 06, 2006 7:55 pm

Post by SomeOtherUser » Wed Feb 14, 2007 6:04 pm

Thanks for the prompt reply.

Code: Select all

import java.awt.Color;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StackedXYAreaRenderer2;
import org.jfree.data.xy.DefaultTableXYDataset;
import org.jfree.data.xy.XYSeries;

public class StackedAreaTransparencyBug {
	
	public static void main(String[] args)
	{
		Color[] tempColors = new Color[COLORS.length];
		
		for(int i = 0; i < COLORS.length; i++)
		{
			tempColors[i] = new Color(COLORS[i].getRed(), COLORS[i].getGreen(), COLORS[i].getBlue(), 128);
		}
		COLORS = tempColors;
		DefaultTableXYDataset dataset = new DefaultTableXYDataset();
		XYSeries series = new XYSeries("series 1", false, false);
		series.add(0,0);
		series.add(1,1);
		series.add(2,0);
		series.add(3,1);
		series.add(4,0);		
		dataset.addSeries(series);
		series = new XYSeries("series 2", false, false);
		series.add(0,0);
		series.add(1,1);
		series.add(2,0);
		series.add(3,1);
		series.add(4,0);
		dataset.addSeries(series);
		series = new XYSeries("series 3", false, false);
		series.add(0,0);
		series.add(1,1);
		series.add(2,0);
		series.add(3,1);
		series.add(4,0);
		dataset.addSeries(series);
		
		NumberAxis xAxis = new NumberAxis();
		NumberAxis yAxis = new NumberAxis();
		
		XYPlot plot = new XYPlot(dataset, xAxis, yAxis, new StackedXYAreaRenderer2());
		JFreeChart chart = new JFreeChart(plot);
		
		for(int i = 0; i < COLORS.length; i++)
			plot.getRenderer().setSeriesPaint(i, COLORS[i]);
    
		new ChartFrame("StackedAreaTransparencyBug", chart).setVisible(true);
	}

    private static Color[] COLORS = new Color[] {Color.decode("#155CAC"), // Blue
    												   Color.decode("#E8B318"), // Yellow
    												   Color.decode("#CE1B1F"), // Red
    												   Color.decode("#0D794D"), // Green
    												   Color.decode("#EA6A1D"), // Orange
    												   Color.decode("#6B0B6B"), // Purple
    												   Color.decode("#19AAB4"), // Light Blue
    												   Color.decode("#7C3B27"), // Brown
    												   Color.decode("#5FB453"), // Light Green
    												   Color.decode("#3D2A85")}; // Dark Purple


}

SomeOtherUser
Posts: 13
Joined: Thu Apr 06, 2006 7:55 pm

Post by SomeOtherUser » Wed Feb 21, 2007 5:55 pm

Were you able to determine if this is a new bug or the same bug? I can't find a post on Sourceforge for this bug; can you point me to it?

Locked