How to display values in ASP.NET chart control

c11ada picture c11ada · Jun 20, 2011 · Viewed 25.6k times · Source

I'm using a dataset as my data source to create a chart in asp.net, iv managed to display a column chart. Im now stuck on how I can display the values of each column on the chart.

Can some one please advice on how I may do this?

Answer

Naveed Ahmad picture Naveed Ahmad · Jun 20, 2011

I am assuming you are using ASP.NET chart controls which come as standard with .net 4, the very basic chart you can get is by below code

<asp:Chart ID="Chart1" runat="server">
    <Series>
        <asp:Series Name="Series1" ChartType="Pie" Palette="EarthTones" >
            <Points>               
                <asp:DataPoint AxisLabel="Celtics" YValues="17" />
                <asp:DataPoint AxisLabel="Lakers" YValues="15" />
                <asp:DataPoint AxisLabel="Bulls" YValues="6" />
                <asp:DataPoint AxisLabel="Spurs" YValues="4" />
                <asp:DataPoint AxisLabel="76ers" YValues="3" />
                <asp:DataPoint AxisLabel="Pistons" YValues="3" />
                <asp:DataPoint AxisLabel="Warriors" YValues="3" />
            </Points>
        </asp:Series>
     </Series>
     <ChartAreas>
        <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true" />
     </ChartAreas>
</asp:Chart>

Now, if you want to access this programmatically, you might want to download the sample project given at http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx and go through the sample code.The project is quite extensive and describes in details about everything you need to know about charts. If you are stuck at a specific logic or piece of code, could you post that so we can advise further

Thanks.