Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2592
  • Last Modified:

c# ASP.Net Chart control

Hi,

I'm trying to use the chart control in ASP.NET 4.0 to show some data from a SQL server DB.
The charts are displaying while on local server but I fail to display them on our web server after deployment.

I have followed all suggestions I can find but still not working.
When I debug using Firebug I see that my temp images ends up right beneath the root instead of into my created folder tempimages.

Here's my web.config

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
  <appSettings>
    <add key="ChartImageHandler" value="storage=file;privateImages=false;timeout=20;Url=~/tempimages/;" />
  </appSettings>
  <connectionStrings>
&#9;<!-- No need to show this one -->
  </connectionStrings>
  <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>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    </authentication>
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <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.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
</configuration>

Open in new window

0
peer754
Asked:
peer754
  • 11
  • 3
  • 3
  • +1
1 Solution
 
Jared_SCommented:
You might be able to save yourself some time by simply storing the images in memory.


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

Open in new window

0
 
peer754Author Commented:
I t didn't make any difference at all I'm afraid, still the same empty chart.

As you can see in attached code below, it still looks for a ChartImg.axd beneath my root.

Here's the runtime code taken from Firebug:

<img style="height:300px;width:1200px;border-width:0px;" alt="" src="/ServerMonitor/ChartImg.axd?i=chart_0702f7573a2c46b09a19a2268208c6e0_4.png&amp;g=f29f33ec359641abb26846e619a5646a" id="ContentPlaceHolder1_Chart1">

Open in new window

0
 
Jared_SCommented:
Does your web server have the right framework?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
peer754Author Commented:
Yes, the web server is a Win 2003 Server with IIS6.0 and .NET Framework 4.0
I thought adding a simple chart to a ASP page should be straight forward?
0
 
peer754Author Commented:
What am I supposed to do to get anymore attention?
0
 
Jared_SCommented:
Your web.config looks identical to working applications I have, should be good.
framework in dev and production is the same and has all the proper references built in.
Storing the temp image to memory eliminates any directory confusion.
Your run time code from firebug looks good.
I assume your data source has valid output on your web server.

Do you have the imagestoragemode set in the properties of the chart?
If so, with temp images storing to memory in your web.config, remove that from your chart properties.

Can you post your .aspx if that doesn't work?
0
 
peer754Author Commented:
My data source has valid output yes, everything still works on localhost.
I've tried both imagestoragemode set to either UseHttpHandler or UseImageLocation

Here's my aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="testChart.aspx.cs" Inherits="ServerMonitoring._testChart" %>
<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table>
        <tr>
            <td>
                <asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1" 
                    Width="1200px">
                <series>
                    <asp:Series Name="Series1" XValueMember="logTime" YValueMembers="freedisk" 
                        ChartType="FastPoint" YValuesPerPoint="2" Color="224, 224, 224" 
                        Palette="SeaGreen" XValueType="DateTime" YValueType="UInt32">
                    </asp:Series>
                </series>
                <chartareas>
                    <asp:ChartArea Name="ChartArea1">
                    </asp:ChartArea>
                </chartareas>
                    <Titles>
                        <asp:Title Font="Microsoft Sans Serif, 8pt, style=Bold" Name="freeDiskTitle" 
                            Text="Free disk [MB]">
                        </asp:Title>
                    </Titles>
                </asp:Chart>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Chart ID="Chart2" runat="server" DataSourceID="SqlDataSource2" 
                    Width="1200px">
                    <Series>
                        <asp:Series ChartType="Point" Name="Series1" XValueMember="logTime" 
                            YValueMembers="cpuload">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                    <Titles>
                        <asp:Title Font="Microsoft Sans Serif, 8pt, style=Bold" Name="Title1" 
                            Text="CPU Load [%]">
                        </asp:Title>
                    </Titles>
                </asp:Chart>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Chart ID="Chart3" runat="server" DataSourceID="SqlDataSource3" 
                    Width="1200px" ImageStorageMode="UseImageLocation">
                    <Series>
                        <asp:Series Name="Series1" ChartType="Point" XValueMember="logTime" 
                            YValueMembers="memory">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                    <Titles>
                        <asp:Title Font="Microsoft Sans Serif, 8pt, style=Bold" Name="Title1" 
                            Text="RAM [MB]">
                        </asp:Title>
                    </Titles>
                </asp:Chart>
            </td>
        </tr>
    </table>
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Home</asp:HyperLink>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" 
         SelectCommand="SELECT [logTime], [serverId], [freedisk] FROM [logServer] WHERE ([serverId] = @serverId)"
         OnSelecting="SqlDataSource1_Selecting">
        <SelectParameters>
            <asp:Parameter Name="serverId" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
         ConnectionString="<%$ ConnectionStrings:dbConnectionString %>"         
         SelectCommand="SELECT [logTime], [serverId], [cpuload] FROM [logServer] WHERE ([serverId] = @serverId)"
         OnSelecting="SqlDataSource1_Selecting">
        <SelectParameters>
            <asp:Parameter Name="serverId" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
         ConnectionString="<%$ ConnectionStrings:dbConnectionString %>" 
         SelectCommand="SELECT [logTime], [serverId], [memory] FROM [logServer] WHERE ([serverId] = @serverId)"
         OnSelecting="SqlDataSource1_Selecting">
        <SelectParameters>
            <asp:Parameter Name="serverId" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

Open in new window

0
 
Roopesh ReddyCommented:
0
 
peer754Author Commented:
Thanks but no and I've already red that post and also tried what's suggested.

Once again, I've spent several hours or even days, searching for a solution, probably red like several dozens of threads every where, including the search results you'll get when googling on this. So, I guess this is gonna be the last place so, where are all the experts?

Today I thought that there might something with my access rights to our SQL server so I put a Gridview on a new page, made some simple sql-query to the same table that holds the data to be shown in my charts and ... it all showed up with no issues so ... back on zero :-(
0
 
peer754Author Commented:
Still nothing? Can someone please give a reason to why I should renew my subscription? This is starting to look like a big fraud :( This is a payed for site where site personel seems to be free to totally ignore the end-users? Still I have not received any as you would expect expertice but only links to free sites, links that I already have come across by googling myself. Just want to let you know but I doubt that anybody cares or about user input! Bye!
0
 
apeterCommented:
We are using same and it working fine. All your settings looks fine. Try with below appsettings. Better to give write persmiision to the folder for the IIS user.

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\inetpub\wwwroot\<siteName>\TempImageFiles\;"/>
0
 
peer754Author Commented:
Thanks apeter,

I think I've already went through trying your suggestion but I will go through it one more time.
I will also start a new VS project with one chart that I will fill with some static data just to see if I can exclude any SQL server dependencies.
I've already verified that the data from the SQL table is accessable by throwing a gridview on a new page but you never know ...

Are you saying that you've implemented my code into your system as-is and that it's working?
0
 
apeterCommented:
Nope , we are using <asp:chart> control with similar settings.
0
 
peer754Author Commented:
Ok, then there must be something really wrong with my project properties or even VS installation?
The code I'm using is presented here in this thread and it's not working on our 2003 server. Any server settings that could cause this? I've already made sure that my web app has appropriate rights, something more I need to set?
0
 
peer754Author Commented:
At runtime, can you see that your chart image (.png) really ends up beneath C:\inetpub\wwwroot\<siteName>\TempImageFiles\ in your case?
0
 
apeterCommented:
Yes, it does.
0
 
peer754Author Commented:
Ok Experts, I found the reason why it didn't work and it didn't have anything to do with the Chart Control as blindly thought from the beginning.
I did add a new page with only one chart that managed to show the data without problem.
I didn't have to use any Temporary folder or such.

The problem was the path to where my pages are stored on the server. On the server there is  an extra subfolder where all pages are stored, when running on local host it didn't.
I use this path to extract the name of the server and forgot to add some simple string manipulation :-o

So much trouble for nothing and it was all my fault, I'm sorry I had to post this thread when it was nothing wrong with Chart at all.

BR,
Peer
0
 
peer754Author Commented:
The solution didn't have anything to do with my original question, I found out by doing a more thourough debugging, which I should have been doing in the first place.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now