Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.net Chart in 10 Simple Steps.

0.00/5 (No votes)
22 Feb 2010 1  
ASP.net chart control is one of the newly introduced controls to the Visual Studio IDE from Visual Studio 2010 onwards. It is a very powerful, yet

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

ASP.net chart control is one of the newly introduced controls to the Visual Studio IDE from Visual Studio 2010 onwards. It is a very powerful, yet easy to use server side control. Let's take an example on how to use it.

Prerequisites:

  • You would need AdventureWorks database. If you don't have one, you can download an appropriate version from here.
  • Visual Studio 2010.

How can I create a simple chart with ASP.net?

Well, it's easy!

  1. Just drag and drop a chart control to your webform.
  2. Click on tasks shortcut ">" on top-right corner of the chart control. On the item "Choose Data Source", select "<New data source...>".
  3. Select "Database" item from data source types and click ok.
  4. Create a new connection to SQL Server or choose one from Web.config. Remember, you should connect to "AdventureWorks" sample database.
  5. Select the radio button "Specify a custom SQL statement or store procedure" and click next.
  6. Select the radio button "SQL statement", paste the following query and click next.

    SELECT     TOP (10) ISNULL(Person.Contact.FirstName, '') + ' ' + ISNULL(Person.Contact.MiddleName, '') + ' ' + ISNULL(Person.Contact.LastName, '') AS [Sales Person],
                          Sales.SalesPerson.SalesYTD AS [Sales]
    FROM         HumanResources.Employee INNER JOIN
                          Person.Contact ON HumanResources.Employee.ContactID = Person.Contact.ContactID INNER JOIN
                          Sales.SalesPerson ON HumanResources.Employee.EmployeeID = Sales.SalesPerson.SalesPersonID
  7. Click the button "Test Query" and then click finish.
  8. Re-size the chart control by dragging--make it more wider and a little taller.
  9. Click on tasks shortcut ">" on top-right corner of the chart control. On the item "X Value Member", select "Sales Person". Similarly, on "Y Value Member", select "Sales".
  10. Save the webform and test it!

You're Done!

Now, you can play with a variety of chart types such as "Line", "Spline",  "FastLine", "Bar", "Column". Once you get your own working chart control, you can evaluate more advanced features.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here