Hi all,
I have been awake 24h now trying to figure this out.
Background:
I have 10 charts on a php page that I need to export to the server as png's
Working:
I got this to work by using the documentation.
<script language="JavaScript" src="../../FusionCharts/FusionCharts.js"></script>
<script type="text/javascript">
function FC_Exported(objRtn){
if (objRtn.statusCode=="1"){
alert("The chart with DOM Id " + objRtn.DOMId + " was successfully saved on server. The file can be accessed from " + objRtn.fileName);
}else{
alert("The chart with DOM Id " + objRtn.DOMId + " could not be saved on server. There was an error. Description : " + objRtn.statusMessage);
}
}
function ExportChart() {
var args = arguments;
for(var i=0; i<args.length; i++){
chartObject = (args[i]);
if ( chartObject.hasRendered() ) {
chartObject.exportChart();
}
}
}
</script>
<body bgcolor="#ffffff">
<div id="chartdiv" align="center">The chart will appear within this DIV. This text will be replaced by the chart.</div>
<script type="text/javascript">
//Create the chart.
var myChart = new FusionCharts("../../FusionCharts/Column2D.swf", "myChart", "400", "300", "0", "1");
myChart.setDataURL("SaveData3.xml");
myChart.render("chartdiv");
</script>
<div id="chartdiv2" align="center">The chart will appear within this DIV. This text will be replaced by the chart.</div>
<script type="text/javascript">
//Create the chart.
var myChart2 = new FusionCharts("../../FusionCharts/Column2D.swf", "myChart2", "400", "300", "0", "1");
myChart2.setDataURL("SaveData2.xml");
myChart2.render("chartdiv2");
</script>
<input type="button" value="Export Charts" onclick="ExportChart()">
</body>
The problem:
I don't setup the chart objects in javascript I use the PHP module and generate the XML on the fly and feed it to the script.
Here are a example of my php code:
$XMLString = "" ;
$XMLString .= "<chart exportEnabled='1' exportAtClient='0' exportAction='save' exportHandler='../resources/FusionCharts/ExportHandlers/PHP/FCExporter.php' palette='1' exportFileName='$myLayout' decimals='1' enableSmartLabels='1' enableRotation='0' showBorder='0' startingAngle='70' paletteColors='218721,0372AB'>";
while($row2 = mysql_fetch_object($resultXML)) {
$myLabel = $row2->result1 ;
if ($myLabel == 'y') { $myLabel = 'Yes' ; }
if ($myLabel == 'n') { $myLabel = 'No' ; }
if ($myLabel == 't') { $myLabel = 'True' ; }
if ($myLabel == 'f') { $myLabel = 'False' ; }
$myValue = $row2->total ;
if ($myLabel != 'NaN') {
fwrite($fh, "$myLabel: $myValue\n");
$XMLString .= "<set label='$myLabel' value='$myValue' isSliced='1'/>";
}
}
$XMLString .= "</chart>";
if ($myGraphType == "SSP") {
?>
<tr>
<td align="center"><?echo renderChartHTML("../resources/FusionCharts/Charts/Pie3D.swf", "", $XMLString, "myChart$myLayout", 600, 300, false);?></td>
</tr>
<?
My charts generate so I know the code is working. The issue is, how do I press a button and export all the images?
I have a list of chart names, but can't get javascript to see the charts on the page.
Please help, I need some sleep