FusionCharts v3.2 provides advanced print management using JavaScript for Mozilla/WebKit/Gecko based browsers like Firefox, Safari etc. Even though displayed properly on screen, printed output had been not proper in these browsers.
FusionCharts JavaScript class offers a separate Print Manger class to take care of this. The implementation of Print Manager is fairly simple. You would just need to add a single line of code in JavaScript which enables Print Manager for all charts present in a web page. Once enabled, all the charts present in a page are prepared to print correctly. When the charts are ready, which can be tracked by listening to an event raised by the Print Manager, you can use browser's File ? Print menu, JavaScript's native window.print() function or Print Manager's advanced function - managedPrint(). In any of these actions, the charts would come-up properly in the print media. The Print Manager internally does the following to achieve this :
Let's now go through a sample code which will provide you first-hand experience of what has been said above.
Code examples discussed in this section are present in Download Package > Code > JavaScript > Basics folder.
<html>In the above code:
<head>
<title>FusionCharts Print Manager</title>
<script type="text/javascript" src="FusionCharts/FusionCharts.js">
</script>
</head>
<body>
<div id="chartContainer">FusionCharts will load here!</div>
<script type="text/javascript"><!--
FusionCharts.printManager.enabled(true); var myChart = new FusionCharts( "FusionCharts/Column3D.swf",
"myChartId", "400", "300", "0", "0" );
myChart.setDataURL("Data.xml");
myChart.render("chartContainer");
FusionCharts.addEventListener (
FusionChartsEvents.PrintReadyStateChange ,
function (identifier, parameter) {
if(parameter.ready){
alert("Chart is now ready for printing.");
document.getElementById('printButton').disabled = false;
}
});
// -->
</script>
<input type="button" onclick="FusionCharts.printManager.managedPrint()"
value="Managed Print" disabled="disabled" id="printButton" >
</body>
</html>
FusionCharts.printManager.enabled(true)managedPrint() function of FusionCharts.printManager classPrintReadyStateChange to the global object FusionChartsNote thatPrintReadyStateChangeevent is a global event. Thus, this event can not be listened from individual chart instance. Hence, onlyFusionChartsstatic class can listen to this event.
parameters event argument contains a property ready. This returns true when the Print Manager is ready to print all charts in a pageNow, if you try printing from File → Print menu or using a button or function that call window.print() function. You can also click "Managed Print" button to print the chart.
isReady() : This function returns true or false based on the status of Print Manger. When the print manager is fully ready with all the equivalent canvas images of all the charts present in a page, it returns true. configure() : This function helps in configuring the Print Manager. It takes an Object as parameter. The object can have the following properties:
enabled : This is a boolean property where you can explicitly define here whether to enable managed printing feature or notinvokeCSS : This is a boolean property which sets whether CSS based print media layout should be created for managed print or not.message : This property takes a string as message. While the print manager is still not ready with the converted images of the charts, this text message is placed instead of the chart images. The default value is "Chart is being prepared for print.". Note that this function should be called before calling FusionCharts.printManager.enabled( true );
To see implementation code snippets using these advanced functions go through API > Functions page.
Please note that Print Manager takes a bit of time to make all the charts ready for printing. It depends on the size of the chart as well as the processing power of the client side computer. If print action is invoked while the Print Manager is not yet ready with the image, the chart does not show up in the print media. However, if the functionmanagedPrint()is called, it automatically waits for the all the chart to get ready before it proceeds to call thewindow.print()function. Hence, it is recommended to callmanagedPrint()function instead of the other actions.
Last Updated
11th of October, 2010