3

can anyone tell me if it is possible to convert a dojo charting object into an îmage file? I need this as I want to export an Excel file from a webpage containing some data and the representing chart.

The only thing I found is http://dojotoolkit.org/reference-guide/dojox/gfx/utils/toSvg.html#dojox-gfx-utils-tosvg

but I do not really know how to proceed with the output of that function.

Thanks you!

gotcha
  • 151
  • 2
  • 14

1 Answers1

3

What you found will work as long as you know what to do with SVG (e.g., rasterize it using Batik or other tools). The main example will work because any chart object has a surface property. So do something like that:

dojox.gfx.utils.toSvg(chart.surface).then(
  function(svg){
    alert(svg);
  },
  function(error){
    alert("Error occurred: " + error);
  }
);

Another alternative is to switch dojox.gfx into Canvas mode, and grab the result as a raster image directly from Canvas. There is no helper for that in Dojo, but it is relatively easy to do.

Eugene Lazutkin
  • 43,776
  • 8
  • 49
  • 56
  • thank you for your answer, but if I understand you correctly, at least the second approach will not work across all (major) browsers as the dojo canvas mode is not supported by IE and Chrome? – gotcha Jan 12 '12 at 16:12
  • The 2nd approach is for Canvas-supporting browsers (all but IE6-8). The 1st approach should work practically on all browsers. – Eugene Lazutkin Jan 13 '12 at 06:58
  • Thank you for your explanation. I will give the first approach a try as I need it working at least on IE7-8, too. – gotcha Jan 13 '12 at 10:51