Hi,
I want to export chart to image including legend. I used the following code, but the exported image has the following limitations.
1) It does not include legend
2) The background of the chart is not reflected in the image. It appears transparent.
Code I used is below.
var pngImage = null;
if (document.getElementById("chart1")) {
pngImage = $("#chart1").igDataChart("exportImage");
//pngImage = $("#chart1").igDataChart("exportImage", 200, 100);
}
//This is to view the exported image in browser
var pngImageSrc = pngImage.src;
document.getElementById("exportedImage").src = pngImageSrc;
I have attached modified file from the sample available in IgniteUI_20122_WithSamplesAndHelp_NoInstallerTrial.zip. Screen shot of original & exported image also attached.
Please let me know how to overcome these limitations.
Thanks
Muhammed
Muhammed I have the same problem. Forgive me for posting a reply that hasn't got a full answer. Here is how one can append canvas's together. http://jsfiddle.net/5b8NH/
I am trying to use this to just plain old create a canvas with the descriptive information I need to the chart image and then use this new canvas for my image. It seems logical, but I have to learn how to do it in javascript.
There's a way to export the canvas image of your dataChart.
I'm currently doing this exporting the canvas images to base64 and sending the data to a web service wich deserializes the image and sends it to the user for download via browser.
To serialize the canvas image you can use this JQuery function on your client side JavaScript code:
//This serializes your canvas image to base64
var img64 = $(yourCanvasObject).toDataURL("image/png");
Then you just have to send the img64 content to the web service.
There's my .ASMX web service code snippet, wich receives the string containing the serielized bas64 image, and a string to name the exported file, and is supposed to deserialize the image, convert it to a png file naming it as indicated, and getting it downloaded to the user via the browser:
I haven't tested this in much scenarios, but it's working fine for me. I hope it can help you as a workaround. (Conceptually, I don't think this is the best way to export a canvas HTML5 image. Using a web service to do this can sound a bit 'annoying', but I think it's even more elegant than making the user right click on the image, and clicking 'Save as..' option.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Drawing;using System.Security;using System.IO;using System.Text;
[WebMethod] /// <summary> /// This Service method provides a way to get base64 serialized img exported to .png format and /// downloaded directly to the browser. /// </summary> /// <parameters> /// base64Img: /// A System.String representing the base64 serialized image. /// </parameters> /// <returns> /// true if the image is correctly exported; otherwise, false. /// </returns> public bool ImageExporter(string base64Img, string fileName) { try { //check for empty string if (!String.IsNullOrEmpty(base64Img)) { //convert the serialized image to a Byte Array Byte[] bitmapData = Convert.FromBase64String(base64Img);
//create a Stream MemoryStream streamBitmap = new MemoryStream(bitmapData);
//generate a bitmap Image Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap));
//send the image SendImageForDownload(streamBitmap, fileName);
//everything went as expected return true; } //no exportation done return false; } catch (Exception ex) { string mes = ex.Message; //error during exportation return false; } }
[SecuritySafeCritical] /// <summary> /// This function modify the HttpResponse in order to get an image downloaded via browser. /// </summary> /// <parameters> /// ms: /// A System.IO.MemoryStream containing a deserialized image. /// imageName: /// A System.String with the file name the image will have when downloaded. /// </parameters> /// This function can throw some exceptions. private void SendImageForDownload(MemoryStream ms, string imageName) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AppendHeader("content-disposition", String.Format("attachment; filename={0}.png", imageName)); HttpContext.Current.Response.ContentType = "image/png"; ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(HttpContext.Current.Response.OutputStream); HttpContext.Current.Response.End(); }
So, resuming. Yo will need:
Hope this helps.
Regards from Barcelona.