0

I have to use charts for a web site and I'm not able to make them work at all.

It seems easy: you declare a sql data source and the chart will use that data source, but it doesn't work. Instead of the chart, a "broken image" picture appears. I've tried using different browsers and placing the sql data source in different places, but it didn't work.

I'm using vs2010, and the sql data source has been tested and it returns the values ok.

Since I can't find the problem in the code, I write it here:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<form id="form1" runat="server">

<h2>Title</h2>

<br />

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionStringChart1 %>" 
    SelectCommand="SELECT [companyID], [numberOfVisits] FROM [Company]">
</asp:SqlDataSource>


<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1">
    <Series>
        <asp:Series Name="Series1" XValueMember="companyID" 
            YValueMembers="numberOfVisits">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

<br />

</form>
</asp:Content>
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
Ana
  • 3
  • 3
  • do you get any errors in the event log? sometimes problems can be associated with the image location used by the chart control not existing or the app pool not having write access. – Zach Green Apr 07 '11 at 12:26
  • any output says error, but I'm not sure if it's the event log... NOTE: I'm using MVC 2, maybe it's important – Ana Apr 07 '11 at 12:47
  • Check the event log for more detailed errors: http://www.devtopics.com/how-to-check-the-application-event-log-for-errors/ – Zach Green Apr 07 '11 at 13:39
  • Checked, but anything important :_( – Ana Apr 07 '11 at 14:02
  • you mentioned that you are using MVC, but the code above is webforms code... – Zach Green Apr 07 '11 at 14:54
  • here is an SO question discussing using it with MVC, maybe it provides some insight for you: http://stackoverflow.com/questions/319835/new-asp-net-charting-controls-will-they-work-with-mvc-eventually – Zach Green Apr 07 '11 at 14:57
  • Ok, so is that? I feel stupid, vs toolbox let me add that chart, so I thought that I could use it with mvc... I'll check that link and reply the results here. Thank you Zach. – Ana Apr 07 '11 at 15:05

2 Answers2

0

In addition to the Register Declaration, you need to modify your web.config file to get the Chart to work.

Edit: changed 'verg' to 'verb'

    <httpHandlers>
       <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    </httpHandlers

and Check to see if you have at the top of your page the Register declaration:

<%@ Register Assembly = "System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
Zach Green
  • 3,421
  • 4
  • 29
  • 32
David Machel
  • 286
  • 2
  • 12
  • Also, if the chart needs to work on a post, POST needs to be added to the verb list in the httphandler, or just change it to verb="*" – Zach Green Apr 07 '11 at 12:31
  • I've already have those lines in both files (web.config and .aspx), so that may not be the problem... is within , is that ok? – Ana Apr 07 '11 at 12:40
  • Ok, sorry, I edit because I've just realised of the verb placement. anyway, it's still not working Those lines are in web.config, they may help – Ana Apr 07 '11 at 12:52
  • is supposed to go inside , which is good. I believe you only need to define verb inside the web.config. Have you tried verb="*" instead of verb="GET,HEAD" (or post) – David Machel Apr 07 '11 at 13:00
  • unfortunately using verb=" * " returns the same result :( – Ana Apr 07 '11 at 13:03
  • by the way, I'm not using any code-behind like Page_Load or something like that because I think that I don't need it, do I? – Ana Apr 07 '11 at 13:07
  • Don't think so, might be a silly thing but i noticed your series has no ChartType, try adding a chart type: – David Machel Apr 07 '11 at 13:46
  • I've added the ChartType and the result is the same, argh! – Ana Apr 07 '11 at 13:56
  • Try changing the version from 4.0.0.0 to 3.5.0.0 or 2.0.0.0 in the httpHandlers add tag – David Machel Apr 07 '11 at 14:36
0

I'm not that into asp charts control but I do recommend Visifire chart control which is powered by silverlight. Look at this example http://www.visifire.com/blog/2009/05/21/creating-silverlight-charts-from-sql-data-using-aspnet-and-visfire/

I managed to do a proof-of-concept within two days, almost one, and succeding in present SQL data (Datasets) in a silverlight chart. Once it's there, visifire is extremly powerful (and free). It gives you possibility to zoom, label datapoints, axellabels, realtime data etc.

If you want to go the manage-code approach you get even more possibilities. good luck. Check out the example link and you realize how easy it is. We use it today with great success.

I forgot to say, you do not need to know how to program RIA/Silverlight xaml...

Magnus Backeus
  • 2,242
  • 17
  • 24