Visual Studio 2010 – The Windows Forms is not death – The Chart Control


Bosanska verzija teksta može se pročitati ovdje.

With releasing the WPF platform, there are good reasons and questions of what will happen with WindowsForms platform.The official said, for this platform are promising and there is no concern, and it will be continue to develop. Needles to say that the WindowsForms is the most common platform. The News coming from the new version of VS 2010 confirm this fact, and this post will be exactly related to new features in WindowsForms. With the new version of Visual Studio 2010 there is a new control: Char Control clip_image002.

This control is located in the System.Windows.Forms.DataVisualization namespace. Looking thought the ObjectBrowser, there is only one control. Probably they will be more in the future.

image

Chart control has support for connecting to external data source, which means that we can use and connect it directly to database, through one of the existing ORM maper (DataSet, LINQtoSQL or EF). In this post, we will make a simple example with applying the Chart control.

At the beginning let’s create Windows Forms application via File-> New -> Project.

image

Create EF model for the Northwind database, with standard tables: Orders and Order_Details.

image

In fact, when you open the Form1 and show the DataSources window, our tables are shown, but the designer does not allow us to drag and drop them in to the form (see picture below).

image

In order to use the DataSources designer window, we need to add these tables as objects of the DataSources. For this purpose choose Add New DataSource button, then choose Object item and choose Next button (see picture below).

image

Then in the next window, select our Tables and finish the wizard.

image

DataSources window now looks like the following picture:

image

We got two new items that can drag on Form1. Drag and drop the DataGrid objects in Form1, and add Chart control from ToolBox as shown in the following picture:

image

Since the DataGrid controls are already connected to bindingsource, it is now necessary to connect the Chart control with Order_Details table. To show data in the graph we need associate columns Quantity and UnitPrice with the chart control members.

To achieve this, it is neccessery chart1.Datasource apply with orders_detailsBidningSource.

image

When we apply the data source to the chart control, we are now able to set how data will be presented.Chart control has a Series property, and within Series property you can find properties for displaying data in X and Y axes (see picture below).

image

With this we finished setting up Chart control.

It is now necessary to load data from the database. Open the Form1.cs file, implement the events Form_Load and ListChanged, similar on the picture below.

image

We see that we have set up two events for the Form1 Load event and ListChanged event for order_DetailsBidnigSource. The second event is necessary to refresh the Chart control.

If you run the project, the result is similar to the following picture.

image

When we change the current row Order table, changes the content is below the table, as well as in the chart control. This example, we implemented Master-Detail relationship with two DataGrid and one Chart control.


About Bahrudin Hrnjica

PhD in Mechanical Engineering, Microsoft MVP for .NET. Likes .NET, Math, Mechanical Engineering, Evolutionary Algorithms, Blogging.

Posted on 23/10/2009, in .NET, CodeProject and tagged , , , . Bookmark the permalink. 12 Comments.

  1. Thank you for those instructions but I have an issue. I’ve been looking to use this control since a long time for a university project but unfortunately I don’t see this control in the toolbox; and I mean anywhere in the toolbox (I’ve inspected every section). How can I make it appear. All the chart controls I have found online relate to VS2008. I am using VS2010.

  2. I am no professional prarmomger, but as an amater I wrote a blog post () where, as the title suggest, I recommended 9 programming books. And our intersection is 0. Odd! But eyeing your list, it is pretty clear we have different coding interests . Although I have to admit that 2 or 3 of the books you highlight seem pretty interesting!Ruben

  3. , an innovative, young and promising company that was founded in 2004 by two creative and
    enthusiastic young programmers. smartphones, i – Phones and
    i – Pods and even i – Pads and tablets in both
    touch screen and handheld mode. While the public may not be as important
    as users of i – Phone, Android looks like a serious candidate, just because of the
    access.

  4. Yesterday, while I was at work, my cousin stole
    my iphone and tested to see if it can survive a thirty foot
    drop, just so she can be a youtube sensation. My iPad
    is now broken and she has 83 views. I know
    this is totally off topic but I had to share it with
    someone!

  5. Now a days we can find there are numerous online
    games available for children to play with. Another classic toy available from the app
    store which is the amazing Etch A Sketch. It successfully combines both puzzle and adventure niches, being
    the ideal app for those who wish to evade daily.

  6. This is really interesting, You are a very skilled blogger.

    I’ve joined your feed and look forward to seeking more of your fantastic post.
    Also, I’ve shared your site in my social networks!

  7. If you look closer, you will notice them surfing in a flirt chat room.
    One thing I have wanted for a long time that seems to not be an option here on examiner.

    All you need to do is a simple research and simply stop at the ones that attract you.

  8. Good day! This post could not be written any better!
    Reading through this post reminds me of my previous room mate!
    He always kept chatting about this. I will forward this page
    to him. Pretty sure he will have a good read. Thank you for sharing!

  9. To help make your home physical appearance a lot better from the road, install a block surface and mulch.

  10. Those shelves could be ideal for my basement.
    I am going to use this desing for arranging my boxes.

  1. Pingback: GPdotNET with new chart control « Bahrudin Hrnjica Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s