No display of generated ASP chart on aspx page in my web application

4.6k Views Asked by At

For my web application created an aspx page which should display the ASP.NET Charts. Able to generate the charts but not displaying on the page. I can see the generated charts in my 'Temp charts' folder.

I am using ASP.Net 4 and .NET Framework 4 and done the following.

Code is:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Web.UI.DataVisualization" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.UI.DataVisualization.Charting" %>
<%@ Page Language="C#" %>
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<script runat="server"> 
protected void Button1_Click(object sender, EventArgs e)
    {
    }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
     <asp:Chart ID="Chart1" runat="server" ImageLocation="~/TempCharts/ChartPic_#SEQ(200,2)" Height="200px" Width="535px" >
      <BorderSkin /> 
        <Series>
          <asp:Series Name="Series1" ChartType="Pie" YValuesPerPoint="2" >
                    <Points>
                        <asp:DataPoint AxisLabel="4 letter" YValues="20,0" />
                        <asp:DataPoint AxisLabel="5 letter" YValues="10,0" />
                        <asp:DataPoint AxisLabel="6 letter" YValues="5,0" />
                        <asp:DataPoint AxisLabel="7 letter" YValues="16,0" />
                    </Points>  
           </asp:Series>
         </Series>
         <ChartAreas>
           <asp:ChartArea Name="ChartArea1"  >
           </asp:ChartArea>
         </ChartAreas>
  </asp:Chart> 
    </div>
   </form>
</body>
</html>

And added the below to web.config:

<appSettings>
     <add key="ChartImageHandler" value="storage=memory;timeout=30;" /> 
</appSettings>

<system.webServer>
    <handlers>
    <remove name="ChartImageHandler" />
    <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
        path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
        System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>

But I am not able to see the Chart on page. Am I missing any?

Solved: Added ImageStorageMode attribute to <asp:Chart> and set value "UseImageLocation" .

2

There are 2 best solutions below

0
On


try to change your appSetting from

<appSettings>
 <add key="ChartImageHandler" value="storage=memory;timeout=30;" /> 
</appSettings>

to this

<appSettings>
 <add key="ChartImageHandler" value="storage=memory;timeout=30;privateImages=false" /> 
</appSettings>

When set to true, the generated image can only be downloaded by its owner if some of the following types of identifications are enforced:

The user is authenticated.
AnonymousID is enabled.
SessionID is available.

The default value is true.

4
On

Here's a complete Web.Config for chart settings:

    <configuration>
        <appSettings>
            <add key="ChartImageHandler" value="storage=file;timeout=30;dir=~/TempCharts/;"/>
        </appSettings>
        <system.webServer>
            <validation validateIntegratedModeConfiguration="false"/>
            <handlers>
                <remove name="ChartImageHandler"/>
                <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </handlers>
        </system.webServer>
        <system.web>
            <httpHandlers>
                <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
            </httpHandlers>
            <pages>
                <controls>
                    <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                </controls>
            </pages>
            <compilation debug="true" targetFramework="4.0">
                <assemblies>
                    <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies</compilation>
        </system.web>
    </configuration>

Compare it to your current Web.Config file and see what's missing, and try to create a new empty project, add the reference to System.Web.DataVisualization.dll and it should add the chart setting automatically to the Web.Config file.

Hope this helps.