in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

WebChart ASP.NET Export

Last post 06-11-2008 12:00 PM by C1_GregL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-09-2008 11:48 AM

    WebChart ASP.NET Export

    Hi,

    I need to be able to provide some sort of export functionality once the web chart is generated on my web page so that the users can either download it as an image or a pdf or something.

     I'm trying to save an image using the GetImage() method. It returns a chart image but this image is not the same chart as on the web page.  

    Could anybody guide me on how I could export the web chart or save it as an image from the web page?

     Thanks

    Nandita 

    Filed under:
  • 06-09-2008 4:38 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 515

    Re: WebChart ASP.NET Export

    C1WebChart renders as an image on the webpage, so you could just right-click and select Save image as...

    If you want to capture that save-as functionality in a button click event, see my attached sample.

    If you want to save the chart into a PDF, you'll have to use C1PrintDocument or C1PdfDocument to create the pdf.  You can add the chart as an image from GetImage() to the pdf document before saving or viewing.  This is also shown in my attached sample.

     

    Hope it helps,
    Greg L

     

    Filed under: , ,
  • 06-10-2008 3:33 PM In reply to

    • anpuri
    • Not Ranked
    • Joined on 06-10-2008
    • Posts 1

    Re: WebChart ASP.NET Export

    Thanks for replying and sending the samples. I had actually tried all this and this works but I am having trouble saving a dynamic chart image.

    I need to set the datasource of the chart at runtime. The chart gets rendered correctly on my page. But when I try to use GetImage method on button click, the image that I get is always a straight line. It does not reflect the image on my page.

     Maybe I'm doing something wrong. Is it possible for you to send a sample where you're setting the datasource of the chart at runtime ???

     Appreciate it!

    Thanks

    NS

    Filed under:
  • 06-11-2008 12:00 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 515

    Re: WebChart ASP.NET Export

    Are you setting the datasource and calling Getimage on the same post back?  That may not work because the chart image hasn't rendered from the data yet.  I could successfully add a button to that sample I posted that created the datasource at runtime.  You'd click this button, and then click the Save Image button, and the chart image would be this data set.

    1. protected void Button3_Click(object sender, EventArgs e)
    2. {
    3. C1WebChart1.Reset();
    4. //Create DataTable
    5. DataTable dt;
    6. dt = new DataTable("Points");
    7. DataRow dr;
    8. DataColumn xcol = new DataColumn("XCOL");
    9. xcol.DataType = System.Type.GetType("System.Double");
    10. dt.Columns.Add(xcol);
    11. DataColumn ycol = new DataColumn("YCOL");
    12. ycol.DataType = System.Type.GetType("System.Double");
    13. dt.Columns.Add(ycol);
    14. Random rnd = new Random();
    15. for (int i = 0; i <= 9; i++)
    16. {
    17. dr = dt.NewRow();
    18. dr["XCOL"] = rnd.Next(0, 100);
    19. dr["YCOL"] = rnd.Next(0, 100);
    20. dt.Rows.Add(dr);
    21. }
    22. C1WebChart1.DataSource = dt;
    23. C1WebChart1.DataBind();
    24. ChartData data = C1WebChart1.ChartGroups[0].ChartData;
    25. ChartDataSeries ds = data.SeriesList.AddNewSeries();
    26. ds.X.DataField = "XCOL";
    27. ds.Y.DataField = "YCOL";
    28. }

     regards,
    Greg L

Page 1 of 1 (4 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.