Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Chart Success: GDI+ Graphics At Work. Part 2
Chart Success: GDI+ Graphics At Work. Part 2
by Ged Mead | Published  03/16/2005 | .NET Newbie | Rating:
Ged Mead

Ged Mead (XTab) is a Microsoft Visual Basic MVP who has been working on computer software and design for more than 25 years. His journey has taken him through many different facets of IT. These include training as a Systems Analyst, working in a mainframe software development environment, creating financial management systems and a short time spent on military laptop systems in the days when it took two strong men to carry a 'mobile' system.

Based in an idyllic lochside location in the West of Scotland, he is currently involved in an ever-widening range of VB.NET, WPF and Silverlight development projects. Now working in a consultancy environment, his passion however still remains helping students and professional developers to take advantage of the ever increasing range of sophisticated tools available to them.

Ged is a regular contributor to forums on vbCity and authors articles for DevCity. He is a moderator on VBCity and the MSDN Tech Forums and spends a lot of time answering technical questions there and in several other VB forum sites. Senior Editor for DevCity.NET, vbCity Developer Community Leader and Admin, and DevCity.NET Newsletter Editor. He has written and continues to tutor a number of free online courses for VB.NET developers.

 

View all articles by Ged Mead...
Picture This

 In Part 1   we created a Pie Chart by drawing directly on to the surface of the form using the form’s Graphics object.   In this article, we are going to create a Bar Chart, again based on some notional sample data - sales figures from six European countries.     However, this time we will draw the Bar Chart inside a PictureBox control.  

 In general, there is little difference between the two approaches – drawing on the form itself or drawing inside the picturebox.

 In this project, we will draw the chart once the user has clicked a Button.  As in Part 1, the display will be redrawn whenever it has been obscured or changed (this is known as "persisting" the drawing).

     In the Pie Chart example we used the form’s OnPaint method to recreate the chart every time a redraw was required.   This approach is absolutely fine  in most situations .  However, in order to add to our range of graphics skills, we are going to tackle the job from another angle, this time using a Bitmap object.  

   If you are completely new to graphics, you may well find some of the topics confusing.  Sometimes there seems to be so many graphics objects, bitmaps, images, drawing surfaces being manipulated one after the other that you completely lose track of what each of them is supposed to be doing.  But with the help of these articles it should all fall into place for you in the end.

   I will explain step by step the graphics procedures which are used to draw the chart.   By breaking much of the code down into quite small steps, I hope to make the various methods easier to follow.   I have also included a fully commented demonstration version in the Visual Studio Solution which is attached to this article.

 

 

 

Sponsored Links