注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

程序员驿站

淘宝店:http://shop106888457.taobao.com

 
 
 

日志

 
 

Chart with a completely transparent background?  

2014-11-07 11:12:53|  分类: JFREECHART |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Chart with a completely transparent background?

Postby onimity ? Fri Mar 02, 2007 11:49 pm


Hi all, 


I am trying to create a pie chart that is just a pie chart on a transparent background. I 

have read through the Developer's Guide and I have tried everything that I can think of

 but I am still getting a solid white background behind the chart and a set of borders 

around that for the title area (though the title is null). can anyone help? 


Thanks 

Anne

onimity

 

Posts: 3

Joined: Fri Mar 02, 2007 11:38 pm

Top

Postby onimity ? Mon Mar 05, 2007 6:49 pm


I did finally figure this out if anyone runs into the same problem. Three necessary steps 

as far as I could tell: 


1) set the background alpha of the polt to 0.0 

2) Set the chart background to a fully-transparent color 

3) ensure that you are exporting the cart to PNG with a method that allows you to specify 

that you should encode transparency. 


what a headache!

onimity

 

Posts: 3

Joined: Fri Mar 02, 2007 11:38 pm

Top

Background Transparency

Postby dschaffer2003 ? Tue Oct 16, 2007 5:43 pm


Hi 


Do you have any sample code for your solution? 


I followed your suggestion combined with example code from: 

http://cephas.net/blog/2006/06/09/trans ... freechart/ 


and came up with the following modification to TimeSeriesDemo2. The background in the 

PNG is black instead of transparent. Interestingly a post from angel_france talks about 

how after JFreeChart 0.9.3 transparency attempts resulted in black. 


public TimeSeriesDemo2(String title) { 


super(title); 

try { 

XYDataset dataset = createDataset(); 

JFreeChart chart = createChart(dataset); 


chart.setBackgroundPaint(new Color(255, 255, 255, 0)); 

chart.setBackgroundImageAlpha(0.0f); 


OutputStream out = new BufferedOutputStream(new FileOutputStream(new File( 


"/home/schaffer/test.png"))); 


KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter(); 

encoder.setEncodingAlpha(true); 

out.write(encoder.encode(chart.createBufferedImage(500, 270))); 

out.close();

dschaffer2003

 

Posts: 14

Joined: Mon Apr 09, 2007 11:07 pm

Top

Postby onimity ? Tue Oct 16, 2007 6:40 pm


Yea, sure... here's what I'm doing: 


JFreeChart chart = ChartFactory.createPieChart(null, dataset, false, false, false); 

PiePlot plot = (PiePlot) chart.getPlot(); 

plot.setSectionPaint(0, new Color(240,0,0,255)); 

plot.setSectionPaint(1, new Color(0,240,0,255)); 

plot.setSectionPaint(2, new Color(0,0,240,255)); 

plot.setSectionPaint(3, new Color(240,240,0,255)); 

plot.setOutlinePaint(new Color(240,240,240,0)); 

plot.setLabelGenerator(null); 

plot.setBackgroundAlpha(0.0F); 

plot.setCircular(false); 

chart.setAntiAlias(true); 

chart.setBackgroundPaint(new Color(240,240,240,0)); 

chart.setBorderVisible(false); 

response.setContentType("image/png"); 

ChartUtilities.writeChartAsPNG(out, chart, 100, 100, true, 80); 


Hope it helps... 


Anne

onimity

 

Posts: 3

Joined: Fri Mar 02, 2007 11:38 pm

Top

Postby dschaffer2003 ? Wed Oct 17, 2007 10:39 pm


That all worked. Thanks! 


Dan

  评论这张
 
阅读(397)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017