I used JFreeChart to create a XYBarChart
, and I want to know if it is possible to make the green bars semi-transparent if there is another set of bars hiding behind it. In other words, perhaps changing the opacity of only the green bars that are on top of the blue ones?
Asked
Active
Viewed 1,261 times
1

BJ Dela Cruz
- 5,194
- 13
- 51
- 84
1 Answers
0
Most renderer implementations have a getItemPaint()
method which is implemented in AbstractRenderer.getItemPaint()
. This method returns the Paint
to use for a specific item (bar) to draw. You can override this method in your own renderer class and implement whatever logic you need to determine the color and transparency of your bars.
For an example see this post on the JFreeChart forum or search the forum for further examples. Basically this is just:
class CustomRenderer extends BarRenderer
{
public Paint getItemPaint (int row, int column)
{
if (/* something */) {
Paint mySpecialColor = new Color(0.0f, 1.0f, 0.0f, 0.5f);
return mySpecialColor;
}
// else just return the "normal" paint for the series
return getSeriesPaint(row);
}
}
hth,
- martin

Martin Höller
- 2,714
- 26
- 44