If you?re new to ASP development or if you?re like myself and have developed applications for many years, and do not routinely revisit all of the controls for every .NET release, if you haven't already, I would strongly suggest reviewing Microsoft?s ASP.NET 4.0 charting controls before purchasing a third party charting control package.
If you?re familiar with the charting components of Excel you will find the ASP Charting controls to provide a similar set of chart templates and functionality. The ASP.NET 4.0 Chart control provides such a rich set of functionality that I would argue that using this control should satisfy the majority of your charting needs.
In this example I will introduce ASP Charting control by showing how quickly you can build a pie chart, associate it to a Sql data source set up the series and display tool-tips.
The basic steps in the is example is:
- Create the data model
- Create web application
- Add a data source
- Add chart control
- Add chart tooltips
Data Model
As with all charting needs we need to have some data to that will be represented by our chart. The following diagram shows the data model that I used for this example:

The data model consists of a products table where a given product is grouped by a product category. As each product has been sold there is a corresponding record of that sale in the Sale table.
Web Application
- Open Visual Studio
- Create a New ASP.NET Empty Web Application
- Add a new Web Form (.aspx) page to the project
- Open the design view for the web form added in the previous step.
Data Source
- With the web form design view visible expand the "Data" section in the tool box
- Drag & drop a new Sql Data Source object onto the body of the web form.
- In the design view select the Sql Data Source object that was just added and click the carrot that appears then select "Configure Data Source".
- Select or create a New Connection string
- After defining your connection string click "Next>"
- On the "Configure the Select Statement" screen select the radio button for "Specify a custom SQL statement or stored procedure
- On the screen "Define Custom Statements or Stored Procedures" make sure the "Select" tab is selected
- Select the radio button for "SQL statement"
- For the data model above use the following SQL statement in the text field:
1: SELECT PC.ProductCategoryName, PC.ProductCategoryID, SUM(S.Price) TotalSales
2: FROM ProductCategory PC
3: INNER JOIN Product P on PC.ProductCategoryID = P.ProductCategoryID
4: INNER JOIN Sale S ON P.ProductID = S.ProductID
5: Group By PC.ProductCategoryID, PC.ProductCategoryName
- Click the "Next>" button
- You can test the query to verify expected results
- Finally click the "Finish button"

Chart Control
- Expand the "Data" section in the toolbox
- Drag/drop a "Chart" control onto the design service in the body of the web form
- Select the Chart control just added to the design surface and select the carrot.
- In the "Choose Data Source" select the Sql Data Source object that was defined in earlier steps
- Set the "Chart Type" drop down to "Pie"
- Set the "X Value Member" to ProductCategoryName
- Set the "Y Value Member" to TotalSales
At this point running the application provides a nice pie chart with the corresponding category labels.

Chart Tooltips
*Adding tooltips is an easy task and one that is commonly requested, and expected by end users.
- Select the Chart control on the design surface
- Open the properties window
- Locate the "Series" property and click the ellipsis to open the "Series Collection Editor"
- In the left pane make sure "Series1" is highlighted
- On the right pane scroll down until you locate "ToolTip"
- Click the ellipsis to open the "String Keywords Editor" dialog
- In the String Keywords Editor dialog click the button "Insert New Keyword"
- Select the option "Y Value as Percentage of Total"
- You can customize the formatting of the tooltips by changing values in the "Format" drop down.
- To create your own custom formatting select the "Custom" option in the "Format" drop down list.
- Click the "Ok" button on Keyword Editor dialog
- Click the "Ok" button on the String Keywords Editor dialog.
- Click the "Ok" button on the Series Collection Editor dialog.
- Run the application you should see tooltips specific to each section of the pie graph.

Hopefully at this point you will feel comfortable exploring the various chart types their associated properties. Microsoft chart control is a fairly simple control with numerous features. In future blogs I will provide additional charting examples.
~Happy Charting~