JFreechart ChartPanel does not receive Transparenent

I want to give the background of the chart a transparent look (not completely transparent, but a bit). Here is my code. I added a few lines of code to add transparency, but I think the ChartPanel not becoming transparent. After writing these lines of code, the backgound diagram appears 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); 
+6
source share
3 answers

I found that I should use transparent color for both the graph and the graph:

 val trans = new Color(0xFF, 0xFF, 0xFF, 0) chart.setBackgroundPaint(trans) plot .setBackgroundPaint(trans) 
+4
source

Since this can be quite platform and version dependent, you can look at setBackgroundImageAlpha() on Plot to get the desired effect.

+2
source

I encountered a similar problem, however, it was solved after setting the background image to 0.0f ie

setBacgroundImageAlpha (0.0f). as it sets the alpha transparency used when drawing the background image.

alpha transparency (ranging from 0.0f to 1.0f, where 0.0f is completely transparent and 1.0f is completely opaque).

This works because PNG (Portable Network Graphics) format supports alpha channel transparency.

The only difference I found between your code and mine was

p.setBackgroundPaint (new color (127, 127, 127, 64)); // your transparency code

p.setBackgroundPaint (new color (255,255,255,0)); // my transparency code

+1
source

Source: https://habr.com/ru/post/913846/


All Articles