Click here to Skip to main content
15,886,137 members
Articles / Chart
Article

ASP.net Chart in 10 Simple Steps.

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL2 min read 9.6K  
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --