We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Export Chart to excel, pdf in ASP.NET


Hi,

I tried to run the Export Chart code sample on your website, but it is showing a lot of errors on javascript. 

Line  :  document.getElementById('download').addEventListener('click', download, false);
Error : Object doesn't support this property or method

Request you to provide solution for this in my project which I have attached.

Attachment: export_2163f996.zip

5 Replies

JA Jayavigneshwaran Syncfusion Team February 27, 2015 09:00 AM UTC

Hi Ankur

Thanks for using Syncfusion product.

We have analyzed this. The below are the steps to be followed to export a chart as image.

·         Render the chart in HTML5 canvas. This is done by setting the below property

[ASPX]

  <ej:Chart ID="Chart1" runat="server" Width="970" Height="600" CanResize="true" EnableCanvasRendering="True">

  </ej:Chart>

·         Add an image/button inside the anchor tag

[HTML]

  <a id="download" download="Chart.png" style="float: right; cursor: pointer;" >

              <img src="export.png" title="Export Chart"  />

       </a>

·         Code the chart as desire

·         On clicking the anchor tag the below method got called

[JS]

function download() {

                    var canvas = $("#Chart1").ejChart("exportChart");

                    var dt = canvas.toDataURL();

                    this.rel='nofollow' href = dt;

                }

document.getElementById('download').addEventListener('click', download, false);

We have also made a sample to export the chart rendered as an image. Find it from the below location.

 http://www.syncfusion.com/downloads/support/directtrac/118334/WebApplication1-1248144484.zip

 

Please let us know if you have any concern.

Thanks,

Jayavigneshwaran




AN Ankur March 2, 2015 07:01 AM UTC

Hi Jayavigneshwaran,

Thanks for your efforts. The link you sent to download sample is not compatible with my VS2010.

But it is the same code that I have written in my project. Request you to refer Webform1.aspx in the solution which I have attached above (export_2163f996.zip).

I am facing issue in the javascript code, line: document.getElementById('download').addEventListener('click', download,false) where it is throwing runtime error: Microsoft JScript runtime error: Object doesn't support this property or method.

You may also refer [Sample.ZIP] which is also the same.

Thanks,
Ankur.

Attachment: Sample_7e564fc3.zip


JA Jayavigneshwaran Syncfusion Team March 3, 2015 06:51 AM UTC

Hi Ankur,

Sorry for the inconvenienced caused.

We have analyzed this. This exception happens because that you are trying to add event to an element before it is appended to DOM.

So, this can be done after the load of DOM. The below code snippet does this.

[JS]

window.addEventListener('load',function(){

   document.getElementById('download').addEventListener('click', download, false);

}

So in this after the load of that web page, element with id “download” is found and click event is bind to it.

The below link shows more details about this exception

Link: http://stackoverflow.com/questions/21262693/addeventlistener-not-working-in-javascript

And we are able to open the provided sample in VS 2010. Kindly check this one again. We have attached sample from the below location

 http://www.syncfusion.com/downloads/support/directtrac/118334/WebApplication1521918410.zip

 

And we have also attached the sample file (Default.aspx, Default.aspx.cs) alone in the below location for your reference
Default.aspx.zip

If you still face any concern, kindly revert back us by modifying the attached sample to replicate the issue. This will help us to fix the issue sooner.

Thanks,

Jayavigneshwaran
 




AN Ankur March 9, 2015 07:27 AM UTC

Hi,

Now there is this error.

PFA error image.

Also the solution you have been sending me is of Visual studio 2012, Framework 4.5 whereas I am using Visual studio 2010, Framework 4.0 this is the reason it was showing incompatible.
I am not able to export chart into image.

Thanks.

Attachment: Chart_export_ce72685a.zip


AT Anandaraj T Syncfusion Team March 10, 2015 09:48 AM UTC

Hi Ankur,

Sorry for the inconvenience caused.

We have modified our sample for Visual Studio 2010 and .Net Framework 4.0 and it can be downloaded from the following link

http://www.syncfusion.com/downloads/support/directtrac/118334/ChartExport-1729911475.zip

Note: Since Internet Explorer does not support client-side downloading due to security reasons, Chart will not be exported client-side in Internet explorer

Please let us know if you have any concern.

Regards,

Anandaraj



Loader.
Live Chat Icon For mobile
Up arrow icon