开发者

Converting Flex Barchart to Image without rendering

开发者 https://www.devze.com 2023-04-11 02:06 出处:网络
Is there a way to create a BarChart (in the background) without adding it to the current view?I basically have a chart that I need to convert to an image and add it to a PDF report (using AlivePDF)开发

Is there a way to create a BarChart (in the background) without adding it to the current view? I basically have a chart that I need to convert to an image and add it to a PDF report (using AlivePDF)开发者_运维技巧.


No, you must add the the chart to the display list.

A DisplayObject must be added to the display list in order to be able to render out as a Bitmap (i.e. to print it or to send it to a PDF).

Internally AlivePDF uses the BitmapData.draw(...); method which requires the object to be on the display list and have visible=true in order to be rendered out.

If you don't want the chart to appear on the stage whilst you are generating your PDF (or printing) then you can add the chart to a parent container and hide the parent instead.

Here is an example of how you can do that:

var box:VBox = new VBox();
// Hide the parent, not the chart.
// If you set chart.visible = false then it won't show up in the PDF.
box.visible = false;
box.addChild(chart);
addChild(box);

// You might need to force validation here so the chart has the correct size.
box.validateNow();

// Add chart to PDF.
pdf.addImage(chart);

// TODO: Clean up your display items here.
box.removeChild(chart);
removeChild(box);
box = null;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号