martinbshp
martinbshp

Reputation: 1173

Charts not rendering ASP.NET

Please help. I am trying to put charts on a aspx page but they don't show when attempting to view in browser. It just shows blank where the charts should be. Here is the aspx code. Thank you.

<h2>Top 5 Most Expensive Products</h2>
<br />
<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1">
    <Series>
        <asp:Series Name="Series1" ChartArea="ChartArea1"></asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
    </ChartAreas>
</asp:Chart>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT TOP 5 [price], [productName] FROM [products] ORDER BY [price] DESC"></asp:SqlDataSource>
<br />
<h2>Total Number of Customers Per State</h2>
<br />
<asp:Chart ID="Chart2" runat="server">
    <Series>
        <asp:Series Name="Series1"></asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
    </ChartAreas>
</asp:Chart>
<br />

Upvotes: 1

Views: 35

Answers (1)

Ted
Ted

Reputation: 4067

You are missing the mapping between the Data coming from you Database and the Series in the Charts.

For that you need to use XValueMember and YValueMember to complete the mapping.

Try something like this:

<Series>
   <asp:Series Name="Series1" ChartArea="ChartArea1" XValueMember="price" YValueMember="productName"></asp:Series>
</Series>

Upvotes: 1

Related Questions