Click here to Skip to main content
15,891,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a situation in a webforms application using the Chart Control where the chart will often display as a broken image, and only sometimes display correctly. This only occurs once I publish the application to the hosting server, it always renders perfectly on my local development environment.

I have posted the demo here. You'll see on each refresh of the page - charts will sometimes render and sometimes not. Is there something I'm missing? Is this a problem with my web hosting provider?

XML
<appsettings> 
      <!--<add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;">-->
  <add key="ChartImageHandler" value="storage=session;timeout=60;privateImages=false;">


ASP.NET
<form id="form1" runat="server">
        <asp:Button ID="btnPostBack" runat="server" Text="Do Postback" OnClick="btnPostBack_Click" />

        <table>
            <tbody><tr>
                <td>Bind On PageLoad
                    <asp:Chart ID="Chart1" runat="server">
                        <series>
                            <asp:Series Name="Series1" Color="LimeGreen">
                        
                        <chartareas>
                            <asp:ChartArea Name="ChartArea1">
                        
                    
                </td>
                <td>Bind On Postback
                    <asp:Chart ID="Chart2" runat="server">
                        <series>
                            <asp:Series Name="Series1" Color="Brown">
                            
                        
                        <chartareas>
                            <asp:ChartArea Name="ChartArea1">
                            
                        
                    
                </td>
                <td>Bind On PageLoad EnableViewState is TRUE
                    <asp:Chart ID="Chart3" runat="server" EnableViewState="True">
                        <series>
                            <asp:Series Name="Series1" Color="Goldenrod">
                            
                        
                        <chartareas>
                            <asp:ChartArea Name="ChartArea1">
                            
                        
                    
                </td>
                <td>Bind On Postback EnableViewState is TRUE
                    <asp:Chart ID="Chart4" runat="server" EnableViewState="True">
                        <series>
                            <asp:Series Name="Series1">
                            
                        
                        <chartareas>
                            <asp:ChartArea Name="ChartArea1">
                            
                        
                    
                </td>
            </tr>
        </tbody></table>
    </form>


C#
protected void Page_Load(object sender, EventArgs e)
{
    BindChart(Chart1);
    BindChart(Chart3);
}


protected void btnPostBack_Click(object sender, EventArgs e)
{
    BindChart(Chart2);
    BindChart(Chart4);
}

private void BindChart(System.Web.UI.DataVisualization.Charting.Chart chrt)
{

    List<chartitem> chartPoints = new List<chartitem>();
    chartPoints.Add(new ChartItem("One", 1));
    chartPoints.Add(new ChartItem("Two", 2));
    chartPoints.Add(new ChartItem("Three", 3));

    chrt.Series[0].XValueMember = "XValue";
    chrt.Series[0].YValueMembers = "YValue";
    chrt.DataSource = chartPoints;
    chrt.DataBind();
}

public class ChartItem
{
    public string XValue { get; set; }
    public double YValue { get; set; }
    public ChartItem(string x, double y)
    {
        this.XValue = x;
        this.YValue = y;
    }
}


What I have tried:

I have tried both memory and session as a storage option. I cannot use file storage as I get permission errors.
Posted
Comments
ZurdoDev 25-Oct-16 12:06pm    
Right-clicking the broken image and choosing to open in a new tab gives an error that the resource cannot be found. Do you have code that is cleaning up the images somewhere?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900