The ASP.NET Chart server control enables you to create ASP.NET pages that include charts for complex statistical or financial analysis. The Chart control supports the following features:
Heavy on the Declarative Syntax
For more information, see Chart Controls on the MSDN Web site. For examples of how to use the Chart control, see Samples Environment for Microsoft Chart Controls on the MSDN Code Gallery and Chart Controls for .NET Framework on the .NET Development Center on the MSDN Web site.
In Microsoft Visual Studio 2010, the ASP.NET Chart control is located on the Data tab of the Toolbox. You can add chart data in the control markup, or you can use data binding to populate the chart dynamically.- Data series, chart areas, axes, legends, labels, and titles.
- Data binding.
- Data manipulation, such as copying, splitting, merging, alignment, grouping, sorting, searching, and filtering.
- Statistical formulas and financial formulas.
- Advanced chart appearance, such as 3-D, anti-aliasing, lighting, and perspective.
- Events and customizations.
- Interactivity and Ajax.
Heavy on the Declarative Syntax
<web:Chart ID="chart" runat="server" Width="300px" Height="150px"
Title="Transportation" Type="Line" EnableLegend="true">
<DataSets>
<web:DataSet Color="ForestGreen" Label="Cars">
<web:DataPoint Value="5" />
<web:DataPoint Value="9" />
<web:DataPoint Value="21" />
<web:DataPoint Value="30" Marker="Arrow" />
<web:DataPoint Value="25" />
<web:DataPoint Value="36" />
</web:DataSet>
<web:DataSet Color="Red" Label="Trucks">
<web:DataPoint Value="7" />
<web:DataPoint Value="3" />
<web:DataPoint Value="13" />
<web:DataPoint Value="13" />
<web:DataPoint Value="16" />
<web:DataPoint Value="25" />
</web:DataSet>
<web:DataSet Color="Orange" Label="Motorcycles">
<web:DataPoint Value="18" />
<web:DataPoint Value="25" />
<web:DataPoint Value="18" />
<web:DataPoint Value="13" />
<web:DataPoint Value="25" />
<web:DataPoint Value="23" />
</web:DataSet>
</DataSets>
</web:Chart>
http://chart.apis.google.com/chart?
chd=t:5,9,21,30,25,36|7,3,13,13,16,25|18,25,18,13,25,23
&cht=lc&chs=300x150&chco=228b22,ff0000,ffa500&chm=a,000000,0,3,10&chtt=Transportation&chdl=Cars|Trucks|Motorcycles
For more information, see Chart Controls on the MSDN Web site. For examples of how to use the Chart control, see Samples Environment for Microsoft Chart Controls on the MSDN Code Gallery and Chart Controls for .NET Framework on the .NET Development Center on the MSDN Web site.
Exploring the ASP.NET 3.5 Chart Controls
The
new Chart Controls for .NET Framework 3.5 enables ASP.NET and Windows
Forms developers to easily create rich and professional-looking data
visualization solutions. The Chart Controls currently contains 25
different chart types with 3-D support for most of them, and all of
these, available for FREE. Amongst the other features found in 3rd
party charting controls, the Chart Controls for .NET framework provides
feature like DataBinding, Data Export, support for Financial and
Statistical data, State Management, Streaming, Serialization and much
more.
To get started, download and install the following in the order given below:
Microsoft Chart Controls for Microsoft .NET Framework 3.5 – assemblies containing the Chart Controls (ASP.NET and Windows Forms)
Microsoft Chart Controls Add-on for Microsoft Visual Studio 2008 – Add as a control in the Visual Studio toolbox and provides IntelliSense for Chart controls.
Once
you have downloaded and installed these components, open Visual Studio
2008. In the Data tab on the Toolbox, observe the new ‘Chart’ control.

To get started, let us create a sample application using the Chart control:
Step 1: Drag
and drop the Chart control from the Toolbox to the Design surface of
Default.aspx. You will see a ‘Column chart’ which looks similar to the
following:

If you click on the ‘Source’ view of the page, you find the following mark up added to the page:
<%@ Register Assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<asp:Chart ID="Chart1" runat="server">
<Series>
<asp:Series Name="Series1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
By
default the ChartType is ‘Column’. In order to change the Chart Type to
either Line, Bar, Pie or any of these 25 chart types; with the Chart
control selected, go to the Properties window > go to ‘Series’ >
Click on the ellipse button(…) > in the ‘Series Collection Editor’,
click on the ‘ChartType’ to view and select a different chart type as
shown below:

For this demonstration, we will keep the ChartType to the default ‘Column’.
We will be binding the chart to some data. For this purpose, we will be using the SqlDataSource.
Step 2:
Click on the smart tag or right click Chart > Show Smart Tag >
Choose a DataSource > New Data Source… > Select Database. We will
keep the default ID for SqlDataSource, SqlDataSource1 and click OK.
Step 3:
On clicking OK, you will be presented with a ‘Configure Data Source’
wizard. Click on ‘New Connection’ to open the ‘Add Connection’. Type
your ‘Server Name’ and ‘Select a database Name’ to connect to. Over
here, I have typed (local) as the ServerName and the database I am
connecting to is ‘Northwind’. Click on ‘Test Connection’ to make sure
that there are no errors connecting to the server. Click Ok.
Step 4:
In your ‘Configure Data Source’, click Next. An option will be
displayed for saving the connection string to the configuration file.
Select the checkbox ‘Yes, save this connection as:’ , type a name for
the connectionstring ‘NorthwindConnectionString’ and click Next.
Step 5: In the ‘Configure Select Statement’ > select ‘Specify a Custom SQL Statement or stored procedure’ > click Next

Type the SQL query to ‘list the count of products in a category’ as shown below:
SELECT
CategoryName, COUNT(*) AS ProductCount FROM Products JOIN Categories ON
Products.CategoryID = Categories.CategoryID GROUP BY CategoryName

Click Next > Finish.
Step 6:
Select the Chart control > Go to the Properties window >
ChartAreas property and click the ellipse (…) button to open the
ChartArea collection editor. Go to the ‘Axes’ property in the ChartArea
Collection Editor and click the ellipse (…) button to open the Axis
collection editor as shown below:

Set
the ‘Title’ of the X axis to ‘Categories’ and the ‘Title’ of the Y axis
to ‘Product Count’. Click OK to close the Axis Collection Editor and an
OK again to close the ChartArea Collection Editor.
With
the Chart control selected, go to the Series property in the Properties
window and click the ellipse (…) button to open the Series collection
editor. Go to the Data Source section and add the XValueMember as
‘CategoryName’ and YValueMembers to ‘ProductCount’. Also set the
‘IsValueShownAsLabel’ to True to display the value of ProductCount on
the columns. Click OK.

Step 7: With the properties set, run the application. You will see a chart as displayed below:

I
am sure all we developers who have used 3rd party Charting solutions in
the past, are going to welcome this awesome control from Microsoft. The
best part is that it is available for FREE. For the ASP.NET MVC
developers, here’s an article that would interest you Combining ASP.NET MVC and ASP.NET Charting Controls.
I have approached this problem by trying to represent the entire chart declaratively right in the aspx code. Here is an example of a line chart:
As you can see, a chart with any sizable amount of data can become very cumbersome. The output of this chart looks like this:

The url used to generate this chart looks like this:
You can change the type of chart being generated through the Type property. Here is an example of a bar chart:

A Venn Diagram:

Pie Chart:

I have approached this problem by trying to represent the entire chart declaratively right in the aspx code. Here is an example of a line chart:
As you can see, a chart with any sizable amount of data can become very cumbersome. The output of this chart looks like this:
The url used to generate this chart looks like this:
You can change the type of chart being generated through the Type property. Here is an example of a bar chart:
A Venn Diagram:
Pie Chart:
No comments:
Post a Comment