The new Chart control can generate charts without a lot of work on your part
November 26, 2008
URL:http://www.drdobbs.com/tools/getting-started-with-the-aspnet-35-chart/212200721
Dan Wahlin (Microsoft Most Valuable Professional for ASP.NET and XML Web Services) is a .NET development instructor and architecture consultant at Interface Technical Training. Dan founded the XML for ASP.NET Developers site, which focuses on using ASP.NET, XML, Silverlight, AJAX, and Web Services on .NET and runs smartwebcontrols.com. Dan has co-authored/authored several different books on .NET, including ASP.NET 2.0 MVP Hacks, Professional ASP.NET AJAX, XML for ASP.NET Developers and is currently working on a new book on Silverlight 2. Dan blogs at http://weblogs.asp.net/dwahlin.
I think it's safe to say that charting is a key part of many applications run on company intranets. People like to see data visually as opposed to viewing it in rows and columns sometimes (especially higher level managers). While there are many third-party solutions available that provide charting solutions, you now have access to a very powerful solution from Microsoft that won't set you back any $$ at all. Translated…it's free! Sure, some of you may think that "free" products aren't good but that's not the case here. The new Chart control can generate visually stunning 2D and 3D charts without a lot of work on your part. In fact, there are over 25 different chart types that you can select for use in your ASP.NET or Windows Forms applications.
To get started using the Chart control you'll need to download and install the following:
Once you've installed the chart controls you'll see a System.Web.DataVisualization.dll assembly in the Global Assembly Cache. Within the assembly's System.Web.UI.DataVisualization.Charting namespace you'll find the new ASP.NET Chart control. Here's a step-by-step look at getting started with the Chart control and binding it to data in a database using the good old SqlDataSource control.
Here's what the ASPX code looks like at this point:
<asp:Chart ID="Chart1" runat="server" Width="600" Height="400" DataSourceID="SqlDataSource1"> <series> <asp:Series Name="Series1" XValueMember="Country" YValueMembers="Column1" ChartType="Column"> </asp:Series> </series> <chartareas> <asp:ChartArea BackColor="NavajoWhite" BackGradientStyle="LeftRight" Name="ChartArea1" ShadowOffset="5"> <AxisY Title="Number of Customers"> </AxisY> <AxisX Title="Countries" IsLabelAutoFit="True"> <LabelStyle Angle="-90" Interval="1" /> </AxisX> <Area3DStyle Enable3D="True" /> </asp:ChartArea> </chartareas> </asp:Chart> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT COUNT(*),Country FROM Customers GROUP BY Country"> </asp:SqlDataSource>
You can show a lot of different types of charts by simply changing the Series ChartType to a different value. Here are examples of Point, Pie, and Line charts:
There's much, much more than can be done including adding multiple series (think of charts on top of charts). Check out the Chart control samples located here to learn more!
Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.