4

I'm trying to extract the SVG content of a zingchart generated via CFCHART and pass it to my server to convert the SVG into a PNG

$('#downloadGraph').click(function() {
    zingchart.EXPORTURL = 'imageexport.cfm'; 
    zingchart.AJAXEXPORT = true;
    zingchart.exec('myChart', 'getimagedata', {
        format : 'png',
        callback : function(sImageData) {
            console.log(sImageData);

        }
    });
});

However I get the following error

Uncaught TypeError: Cannot call method 'zcExec' of null 
cfchart-lite.js:1
zingchart.exec_flash cfchart-lite.js:1
zingchart.exec cfchart-html.js:165

I know that the feature works because if you right click on the graph and select 'export to PNG' it works, but i want to put a button on my page to do the same action.

froadie
  • 79,995
  • 75
  • 166
  • 235
  • Where does function zcExec exist and how are you trying to call it? – Dan Bracuk Jan 08 '13 at 23:38
  • it exists in cfchart-lite.js this is the built-in ColdFusion wrapper for zingchart. – user1959684 Jan 09 '13 at 00:24
  • Are you using ColdFusion 10? Are you using a CFChart format of 'html'? I found this: [ColdFusion 10 uses ZingCharts as its client side charting engine when you specify ChartType='HTML' and falls back on the older java charting engine for other types](http://blog.davecozens.com/coldfusion-10-now-uses-zingcharts-for-cfchart-sometimes). – Miguel-F Jan 09 '13 at 14:37

1 Answers1

3

I solved the problem. You can't call getImageData unless the rendering mode is canvas. As I'm using 'SVG' it returns -1. However, I think the cfchart-lite.js is not handling this return value properly.

The way is solved this was to use saveasimage instead

zingchart.EXPORTURL = 'imageexport.cfm'; 
zingchart.AJAXEXPORT = true;

zingchart.exec('datasetChart', 'saveasimage', {
        format : 'png',
        callback : function(sImageData) {
            console.log(sImageData);

    }
});
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • (Edit) Thanks for posting the answer. So are you using this code in conjunction with a cfchart or did you create your own chart as well? Reason for asking is the api says saveasimage "Only works if exportimageurl is set in zingchart.render." . That property does not seem to accessible from cfchart, from what I can tell. – Leigh Jan 09 '13 at 23:29