我想给图表背景一个透明的外观(不完全透明,但有点).这是我的代码.我添加了一些代码行来添加透明度,但我猜ChartPanel没有透明化.编写这些代码行后,图表背景显示为灰色.
JFreeChart chart = ChartFactory.createPieChart3D( "Full traffic view",pieDataset,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,64)); // tranparency code p.setBackgroundImageAlpha(0.0f); p.setSimpleLabels(true); p.setLabelGenerator(null); p.setBackgroundPaint( new GradientPaint(0,Color.white,100,Color.white)); p.setDarkerSides(true); ChartPanel frame1 = new ChartPanel(chart); ChartPanel.setVisible(true); ChartPanel.add(frame1); ChartPanel.setSize(640,400);
解决方法
我发现我必须为图表和情节使用透明色:
val trans = new Color(0xFF,0xFF,0) chart.setBackgroundPaint(trans) plot .setBackgroundPaint(trans)