macsig
Posts: 8
Joined: Tue May 10, 2011 6:25 am

Saving chart as image using only JS

Hello all,
Starting from this post (http://highslide.com/forum/viewtopic.ph ... 40&p=45102) I'm trying to export a chart as image (png) using only JS.

Below my JS code

Code: Select all

</script><script src="/javascripts/highcharts/highcharts.js" type="text/javascript">
</script><script src="/javascripts/highcharts/exporting.js" type="text/javascript">
</script><script src="/javascripts/rgbcolor.js" type="text/javascript">
</script><script src="/javascripts/canvg.js" type="text/javascript">
</script><script src="/javascripts/base64.js" type="text/javascript">
</script><script src="/javascripts/canvas2image.js" type="text/javascript">

<script type="text/javascript">
var chart;
$(document).ready(function() {
  chart = new Highcharts.Chart({
    chart: {
      renderTo: 'Mycontainer',
      defaultSeriesType: 'line'
     },
     ...
  });
  $('#thebutton').click(function() { 
    var mysvg = chart.getSVG();
    var c = document.getElementById('mycanvas');
    canvg(c, mysvg, { ignoreMouse: true, ignoreAnimation: true });
    Canvas2Image.saveAsPNG(c, false);  
  });
});
</script>
And here the simple html

Code: Select all

<div id="Mycontainer" style="width: 800px; height: 400px; margin: 0 auto"></div>
<button class="button" id="thebutton">PNG</button>
<canvas id="mycanvas" width="800px" height="400px" style="display: none"></canvas> 


From my understanding Canvas2Image.saveAsPNG() should save the image server side(http://www.nihilogic.dk/labs/canvas2image/), however when I click thebutton the image is shown in the browser.


Am I missing something?

Thanks for your help, I appreciate it.

Sig
macsig
Posts: 8
Joined: Tue May 10, 2011 6:25 am

Re: Saving chart as image using only JS

Any ideas at all?

I appreciate any suggestion.

Thanks and have a nice weekend

Sig
hfrntt
Posts: 6393
Joined: Mon Aug 30, 2010 8:41 am
Contact: Website

Re: Saving chart as image using only JS

It's not official highcharts feature so I advice to ask the author of the original post.
Slawek Kolodziej
Highcharts support team

Return to “Highcharts Usage”