How to export Asp.net Chart control execl or pdf?

Answered How to export Asp.net Chart control execl or pdf?

  • Donnerstag, 12. Februar 2009 09:57
     
     

    webpage contains Asp.net Chart Control and Gridview with other controls.
    I want to export this page to pdf or excel.if i export to excel am only getting gridview,not getting Chart in that place am getting "X" Symbol.
    Can you please help me out in this issue...

    Thanks
    Vijayanand Gawle

    vijayanand.gawle@gmail.com
    www.vijayanand.tk
    +91-9866492976

Alle Antworten

  • Donnerstag, 12. Februar 2009 22:02
    Besitzer
     
     Beantwortet
    I'm not sure how you are exporting your HTML page... Chart is rendered as an image tag and it points to the server for the actual chart image. It looks like this link is not valid.

    You can always save chart control into an image using Chart.SaveasImage method.

    Alex.


    http://blogs.msdn.com/alexgor
  • Freitag, 10. April 2009 07:44
     
     

    Thanks alex,


    am using export method for exporting chart to excel but getting image tag  but not image.

    in excel file i got  line as data but not the orignal chart.

    Please help me out .....

     

    <img id="Chart2" BorderDashStyle="Solid" src="/2kGamesDemo/ReportsEX1/ChartImg.axd?i=chart_0_0.jpeg&amp;g=a299e5c29e0f42b38fb6f06bcd7a3c86" alt="" style="height:296px;width:709px;border-width:0px;" />



    Following code for export image to excel.

    protected

    void Export()

    {

    Response.Clear();

     

    StringWriter sw = new StringWriter();

     

    HtmlTextWriter htw = new HtmlTextWriter(sw);

     

    //Page.RenderControl(htw);

     

    //.RenderControl(htw);

    Chart2.RenderControl(htw);

    Response.ContentType =

    "aapplication/vnd.ms-excel";

    Response.AddHeader(

    "content-disposition", "attachment; filename=MypdfFile.xls");

    Response.Write(sw.ToString());

    Response.End();

    }


    Drawing chart on page

     

    void DrawChart()

    {

     

    DataSet myDataSet = new DataSet();

    myDataSet.ReadXml(Server.MapPath(

    "Bugsreport.xml"));

     

    int Count=1;

     

    foreach (DataRow row in myDataSet.Tables[0].Rows)

    {

     

     

    // For each Row add a new series

     

    //string seriesName = row["A"].ToString();

     

    string seriesName = Count.ToString();

    Chart2.Series.Add(seriesName);

    Chart2.Series[seriesName].ChartType =

    SeriesChartType.Line;

    Chart2.Series[seriesName].BorderWidth = 2;

     

    // Chart2.Series[seriesName].XValueMember = row["Date"].ToString();

     

    //string xyz = Chart2.Series[seriesName].XValueMember = row["Date"].ToString();

     

    // Chart2.Series[seriesName].XValueMember = row["Date"].ToString();

     

    // Chart2.Series[seriesName].YValueMembers = row["A"].ToString();

     

    // Chart2.Series[seriesName].Points.AddXY(row["Date"], row["A"]);

     

    for (int colIndex = 1; colIndex < myDataSet.Tables[0].Columns.Count - 1; colIndex++)

    {

     

    // For each column (column 1 and onward) add the value as a point

     

    string columnName = myDataSet.Tables[0].Columns[colIndex].ColumnName;

     

    string xyz = (string)((row["Date"].ToString()));

     

    int YVal = int.Parse((row[columnName].ToString()));

     

    //Chart2.Series[seriesName].YValueMembers = row["Date"].ToString();

    Chart2.Series[seriesName].Points.AddXY(Chart2.Series[seriesName].XValueMember = row[

    "Date"].ToString(), YVal);

     

     

     

    // Chart2.Series[seriesName].Points.AddXY(row["Date"], YVal);

    }

    Count = Count + 1;

     

    //break;

     

    //Chart2.Series[seriesName].XValueType(row["Date"]);

     

    }

     

    String FileLoc = Server.MapPath("AspNetChartControl") + System.Guid.NewGuid().ToString()+".png";

    ViewState[

    "FileLoc"] = FileLoc;

    Chart2.SaveImage(FileLoc);

     

    }


    and


    Vijayanand Gawle vijayanand.gawle@gmail.com www.vijayanand.tk +91-9866492976
  • Donnerstag, 2. August 2012 09:42
     
     

    i need export charts which is in a div tag.. how is it possible?

    regards

  • Donnerstag, 21. Februar 2013 12:38
     
     Vorgeschlagene Antwort
    You can use report viewer control and add rdlc report with chart in report viewer control. Report viewer control comes with export to PDF and excel

    • Bearbeitet Haseet Santoki Donnerstag, 21. Februar 2013 12:39
    • Als Antwort vorgeschlagen Haseet Santoki Donnerstag, 21. Februar 2013 12:39
    •  
  • vor 7 Stunden 3 Minuten
     
     Vorgeschlagene Antwort
     StringWriter sw = new StringWriter();
     HtmlTextWriter h = new HtmlTextWriter(sw);
     Div.RenderControl(h);
     string s = sw.GetStringBuilder().ToString();
    • Als Antwort vorgeschlagen Teja Swaroop1 vor 7 Stunden 3 Minuten
    •