0

how to get chart's image as file or stream?

asked 2014-09-10 12:36:06 +0800

PeterPYWu gravatar image PeterPYWu
3

updated 2014-09-10 12:36:45 +0800

Hi,

Does ZK Charts provide any method to get chart's image as file or stream? The scenario is when user clicks the "Export to excel" button, we need to attach this image to excel file automatically.

Thanks.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-09-20 11:10:28 +0800

Darksu gravatar image Darksu
1991 1 4

Hello PeterPYWu,

In the following url there is an example of how to create a BufferedImage from a chart:

http://books.zkoss.org/wiki/SmallTalks/2006/June/IntegratingJFreeCharttoZKFramework,Part_I

Code Sample:

JFreeChart chart = ChartFactory.createPieChart3D("Sample Pie Chart 3D", pieDataset,true,true,true);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setForegroundAlpha(0.5f);
BufferedImage bi = chart.createBufferedImage(500, 300, BufferedImage.TRANSLUCENT , null);
byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

You could use this object in order to export it to a excel file as shown below:

http://www.mysamplecode.com/2012/06/apache-poi-excel-insert-image.html

Best Regards,

Darksu

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-09-10 12:36:06 +0800

Seen: 19 times

Last updated: Sep 20 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More