0

I need to save object HTMLImageElement in excel file. I am using highchart and get the image of the chart by getSVG method (Overall process in [http://willkoehler.net/2014/11/07/client-side-solution-for-downloading-highcharts-charts-as-images.html][1])

Now i am trying to write this image into excel file. for doing that i need to pass the image by webservice but i am stuck into overall process. what i have tried is the following:

var svg = chart.getSVG({
                 exporting: {
                     sourceWidth: chart.chartWidth,
                     sourceHeight: chart.chartHeight
                 }
             });             

             var canvas = document.createElement('canvas');
             canvas.height = render_height;
             canvas.width = render_width;

             var image = new Image;
             image.onload = function () {
                 canvas.getContext('2d').drawImage(this, 0, 0, render_width, render_height);                  
                 var data = canvas.toDataURL("image/png")
                 download(data, filename + '.png');
             };



        var dataitem= JSON.stringify({ data: image});

        $.ajax({
            type: "POST",
            contentType: "application/json;charset=utf-8",
            datatype: "json",
            data: dataitem,
            url: "FrontDesign/Sendimage",
            success: function (data) {
                 //code for success
            }
        });

I know JSON.stringify({ data: image}) is not process to pass. Any Suggestion regarding this matter?

MAT14
  • 129
  • 4
  • 17
  • The `JSON.stringify()` and the following `$.ajax()` have to go into the `onload` callback of your image. – Sirko Aug 04 '15 at 11:46
  • You can pass the base64 value to your ajax POST data: var pngUrl = canvas.toDataURL(); var dataitem= JSON.stringify({ data: pngUrl}); Also be sure to get pngUrl in the callback of onload – tdebroc Aug 04 '15 at 11:49

0 Answers0