Alpha-Transparency for Legend
Alpha-Transparency for Legend
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
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
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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));
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
-
- Posts: 13
- Joined: Thu Apr 06, 2006 7:55 pm
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).but still on the chart we have a new color wich is the addition of the 2 where is stacked ... Sad
Is this a bug or intended rendering? Is there a way to prevent the overlap?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.SomeOtherUser wrote:Is this a bug or intended rendering? Is there a way to prevent the overlap?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 13
- Joined: Thu Apr 06, 2006 7:55 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
}
-
- Posts: 13
- Joined: Thu Apr 06, 2006 7:55 pm