Create 3D Charts and Graphs in .NET applications with MS Chart Control


Creating charts and graphs in .NET applications were no easy task before the release of Microsoft Chart Controls. It is now very simple and easy to create charts and graphs in .NET applications with Microsoft Chart Control that is embedded in Visual Studio 2010. The bad news is this is not supported in .NET framework 2.0. If you are lucky enough to work in .NET framework 3.5 or higher, then you can use this chart control to generate all kind of charts instantly.

If you are using Microsoft Visual Studio 2008, you can still install the add-on available for this chart control and include this chart control in your project. Let me explain in simple steps on how to create charts in windows form application to represent data from a sample access database in few easy steps.

Install Microsoft Chart Control in Visual Studio 2008

If you are using Visual Studio 2010, then you can skip this section and proceed to the next section.

1. Download MSChart_VisualStudioAddon.exe from here.

2. Run the executable file and install it. 

3. Now go to ToolBox, Right Click on it, Select 'Choose Items'


4. You will find two Chart controls, one for web application and the other for Windows application. Click on the checkbox near the appropriate chart control based on your type of project. 



Now you can see the Chart Control under the 'Data' category of your toolbox as shown below.

Create Charts & Graphs in Windows Forms Application Using Access Database


1. To Start with, I have created a sample database in the name CompanyRevenue in Microsoft Office Access. I also created a table in the name 'CountryRevenue' with three fields namely ID, Country and Revenue. This table consists of data that gives the revenue generated by the company's products in each country.


2. Create a new windows forms application and add chart control to the form by dragging and dropping the Chart Control on to your form.


3. You can see a sample bar chart appearing on your form in the design view. All you have to do now is just add the data to this chart and change some of the visual properties that would alter the way your chart is rendered. To do this,
  • Right Click on Chart Control and Select 'Properties'.
  • In the 'Properties' window, Click on 'Datasource' -> Add Project Data Source.


  • This will pop up 'Database Configuration Wizard' shown below.

          Select 'Database' -> Click Next -> Select 'DataSet' -> Click Next -> New Connection
  • This will open 'Add Connection' wizard.

          Select "Microsoft Access Database File (OLE DB)" as Datasource and give the path 
          of the access database you are going to use in the 'Database File Name' textbox. 
          I have given the path of the CountryRevenue Database I created previously. 
          Click on "Test Connection" button and if you get an alert saying "Test 
          Succeeded", you are good to proceed with the next set of configurations.
          Click 'OK'.
  • After you click 'OK' on the 'Add Connection' dialogue, the wizard will prompt you to include the necessary data objects for this data source. Here I am going to use 'Coutry' and 'Revenue' columns from country_revenue table. See screenshot below for reference.

         Click on 'Finish' to complete database configuration.
  • In the 'Properties' window, click on 'Series'. You will find a collection of properties under 'Series' -> Go to 'Data Source' -> 'XValueMember -> Select 'Country'. This means that X axis is going to represent values from 'Country' Column of the table. Do the same for 'YValeMember' and select 'Revenue'.

  • To provide text to be displayed on the X and Y axes of your chart, in the 'Properties' window, click on 'Chart Area'. You will find a collection of properties under 'Chart Area'. Now from here click on 'Axes' property.

In 'Axes Collection Editor' dialogue, find the 'Title' Property and edit the title text for both 'X' and 'Y' axes. In the below screenshot I have set the 'Title' property for X axis to be 'Country'.


Thats it! We are good to run the project to view the generated chart with values from our database.

See the output chart in the below screenshot.



Create 3D charts using MS Chart Control

The above output clearly represents the data from our database but the chart is not a 3D chart though. Creating 3D charts is very simple, easy and can be done by just setting 'Enable3D' Property to 'True'. To do this, right click on the chart control -> Properties -> Chart Area -> Area 3D Style -> (Enable3D) -> True. See screenshot below.


Now we have 3D chart in our output.


Change type of Chart Displayed

You can generate many types of charts such as bar chart, pie chart, line graph, point graph etc. by following the above steps in addition with setting one more property to specify the type of chart displayed. 

To select the type of chart you want to display, 
1. Right click on the chart control -> Properties 
2. Properties -> Series -> Chart -> Chart Type
3. Select the chart type you require from the drop down list and run the project.



Output with Different type of Charts

PieChart


AreaChart

Line Graph



I hope this post helped you to understand how simple it is to create different kinds of charts and graphs in dot net application using Microsoft Chart control. Please leave your comments and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. Thanks for reading this!!



Subscribe to GET LATEST ARTICLES!


advertise here

Related

Dot Net 8377261109445881378

Post a Comment

  1. really nice article to understand Chart control

    ReplyDelete
  2. very good article for starting with chart controls:)

    ReplyDelete
  3. I go through the same process and at last i couldnot found the chart control in my toolbox....please help me.

    ReplyDelete
    Replies
    1. What is the version of Dotnet framework you are using? Microsoft charts are supported only in .net framework version 3.5 or higher as I have mentioned already.

      Delete
  4. The MS chart control is actually a stripped down version of Dundas chart, which never really had a true 3D. As a result it cannot display most of the usable 3D charts like surface, xy scatter point or vector field. Unfortunately charts that can do similar stuff are pricey - Nevron Chart (www.nevron.com) or Devexpress (www.devexpress.com) and I wonder if MS will do something similar to extend their control...

    ReplyDelete

emo-but-icon

Currency Converter

Built using AngularJS and ASP.NET Web API

SUBSCRIBE


item