3

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" .

EHVR
  • 33
  • 2
  • 7
  • Wait, why are you insterting c# snippets in the aspx page? use the codebehind, it's clearer! What IDE are you using? Also I can perfectly see it. –  May 23 '14 at 14:24
  • I am implementing this in my web application. I have some restrictions to use .cs files. I am not using Visual Studio for this. – EHVR May 26 '14 at 07:11

2 Answers2

1


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.

Claudio
  • 11
  • 1
0

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.

jack
  • 1,103
  • 2
  • 10
  • 18
  • Added the missing lines to web.config. But the result is same. – EHVR May 26 '14 at 07:22
  • that's odd, do you see any error message? you said you don't use visual studio for this, what are you using? – jack May 26 '14 at 07:43
  • Inside my web application I can implement/add aspx pages.It is a .NET application. Added ImageStorageMode="UseImageLocation" attribute to and it worked. – EHVR May 26 '14 at 08:40
  • glad it worked for you, please update your question with your solution so that others can benefit from it in the future :) – jack May 26 '14 at 08:43