Hi,
I am trying to export chart as an image using below code (from documentation):
var pngImage = $('chartDiv"]').igDataChart("exportImage", 200, 100);
I am just stuck here. I want a image of chart. I am not sure how to get that.
Any help would be appreciated.
If pngImage in your code above is actually an html dom image that you can add to the page. If you have some other purpose, you can examine the data url that was exported by the canvas by reading pngImage.src. What you do with this depends on the scenario you are trying to enable. What are you trying to accomplish?
-Graham
Hi Graham,
I am trying to save Chart as an image on click of Chart.
So I have a click handler to save image as shown below:
//save chart as image on Click $('#DataChart').click(function() { var pngImage = $(this).igDataChart("exportImage", 200, 100); });
However I am not sure how the image would be saved, since the above line does nothing. I thought it would save the image somewhere in application folder or download directory.
I want it to ask for filename (filed dialog) before saving image. I just used the piece of code that I found in documentation. Please assist me how to achieve image save.
Hi Graham, Any update on this ?????
Hi, the function of that member in our api is to provide an image DOM element that you can use. There isn't a direct way to use that or the data url that is its src attribute to save to disk.
There are various people that have explained how to take a data url and save it to disk though:
http://www.nihilogic.dk/labs/canvas2image/
Essentially if you grab the src of the image that you get back from exportImage, you could feed it into the logic presented on that site and it would let you save an image to disk.
If you would like this sort of thing baked into the product, please make a feature request.
Let me know if you have any issues.
Also see:
http://stackoverflow.com/questions/11645468/how-to-save-an-image-file-with-the-src-i-have-created-by-drawing-on-html-5-canva
Thanks for the link. The link shows how to get image for PHP.
Any ideas how that could be implemented in Asp.Net MVC 3.
Below is the code:
var pngImage = $("#mChart").igDataChart("exportImage"); var pngImageSrc = pngImage.src; pngImageSrc = pngImageSrc.replace('data:image/png;base64,', '');
Now I am passing pngImageSrc to MVC Action and converting it to byte[] and returning File object from Action.