I want to give the chart background a transparent look (not fully transparent but a little bit). Here is my code. I have added few code lines to add transparency, but I guess the ChartPanel
is not getting transparent. After writing those code lines, the chart backgound is appearing gray.
JFreeChart chart = ChartFactory.createPieChart3D(
"Full traffic view", pieDataset, true, true, true);
PiePlot3D p = (PiePlot3D) chart.getPlot();
PieRenderer renderer = new PieRenderer(sampleColors);
renderer.setColor(p, pieDataset);
p.setDepthFactor(0.07);
p.setCircular(true);
p.setLabelOutlinePaint(null);
p.setLabelBackgroundPaint(null);
p.setLabelShadowPaint(null);
p.setBackgroundPaint(new Color(127, 127, 127, 64)); // tranparency code
p.setBackgroundImageAlpha(0.0f);
p.setSimpleLabels(true);
p.setLabelGenerator(null);
p.setBackgroundPaint(
new GradientPaint(0, 0, Color.white, 0, 100, Color.white));
p.setDarkerSides(true);
ChartPanel frame1 = new ChartPanel(chart);
ChartPanel.setVisible(true);
ChartPanel.add(frame1);
ChartPanel.setSize(640, 400);
I found that I have to use a transparent color both for chart and plot:
val trans = new Color(0xFF, 0xFF, 0xFF, 0)
chart.setBackgroundPaint(trans)
plot .setBackgroundPaint(trans)
Because this can be rather dependent on platform and version, you might look at setBackgroundImageAlpha()
on the Plot
to get the desired effect.
I faced the similar problem however it got solved after i set the background image to 0.0f i.e
setBacgroundImageAlpha(0.0f). since it Sets the alpha transparency used when drawing the background image.
the alpha transparency (in the range 0.0f to 1.0f, where 0.0f is fully transparent, and 1.0f is fully opaque).
This works because the PNG (Portable Network Graphics) format supports alpha channel transparency.
The only difference i found between your code and mine was in
p.setBackgroundPaint(new Color(127, 127, 127, 64)); // your tranparency code
p.setBackgroundPaint(new Color(255,255,255,0)); // my transparency code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With