locked
Create chart in code behind and display it RRS feed

  • Question

  • hi,

    this is my code:

    double[] yValues = { 15, 60, 12, 13 };
    string[] xValues = { "September", "October", "November", "December" };
    
    
    // Create a pie chart
     Chart chart = new Chart();
    
    
    // Build a pie series
    Series series = new Series("Default");
    series.ChartType = SeriesChartType.Pie;
    series["PieLabelStyle"] = "Disabled";
    chart.Series.Add(series);
    
    
    // Define the chart area
    ChartArea chartArea = new ChartArea();
    ChartArea3DStyle areaStyle = new ChartArea3DStyle(chartArea);
    areaStyle.Rotation = 0;
    
    
    Axis yAxis = new Axis(chartArea, AxisName.Y);
    Axis xAxis = new Axis(chartArea, AxisName.X);
    
    
    // Bind the data to the chart
                    chart.Series["Default"].Points.DataBindXY(xValues, yValues);
    
    
    // Save the chart as a 300 x 200 image
    chart.Width = new System.Web.UI.WebControls.Unit(300, System.Web.UI.WebControls.UnitType.Pixel);
    chart.Height = new System.Web.UI.WebControls.Unit(200, System.Web.UI.WebControls.UnitType.Pixel);
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
    chart.SaveImage(System.IO.Stream.Null);
    chart.SaveImage(ms, ChartImageFormat.Png);
    Session["GraficoClientePorTipo"] = ms.ToArray();
    
    divInferior.Controls.Add(new LiteralControl("<div>" + chart.GetHtmlImageMap("GraficoClientePorTipo") + "</div>"));

    my problem is the chart doens't appear in my div and I can't put <asp:chart> in the side page.aspx.

    thanks for help

    Monday, April 27, 2015 4:37 PM

Answers

  • Hi  lizie,

    According to your code, I see you used some code from Web application. For web project issue, you should post in Asp.Net forum.

    http://forums.asp.net/

    Thanks for your understanding.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Just Karl Tuesday, April 28, 2015 8:09 PM
    • Marked as answer by Just Karl Wednesday, May 6, 2015 3:49 PM
    Tuesday, April 28, 2015 6:21 AM