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...
The next logical step would be to create a Chart Class and a Class Library to make your code more portable between applications.
Following that, if you are expecting to have to use many of these kinds of charts many times in the future then the best long term plan might well be to create your own custom control and add it to your Visual Studio Toolbox.
For the time being though, we will settle for this set of generic line chart procedures. The Class Library and User Control will have to wait for a later date.
Nevertheless, we have covered quite a lot of ground in this article and have produced a useful way of creating dynamic line charts. We have certainly come a long way from our first simple Pie Chart back in Part 1!
In this article, we covered the following topics:
- Dispose method
- Double Buffering
- DrawLine method
- DrawImage method
- FillPolygon method
- Font object
- Format menu item
- Graphics.FromImage method
- TranslateTransform method
Demonstration Sample Solution
All the code described is included in the attached sample solution, which was created using VB.NET 2003.
It's taken me a while to complete all six articles in this set, but I hope that they have helped you go from the very basic out-of-the-box pie chart to the potentially quite sophisticated dynamic line charts. Of course, there are lots of other charts we could consider and many enhancements to what we have done so far, but I'll leave you to take it on from here. If you have any questions about any of the techniques don't hesitate to post them up in the VB.NET Forum and I'll do my best to help out.
Acknowledgements: I would like to thank Rod Stephens of VBHelper for the original idea of cutting and pasting a Bitmap to an offset position to create the illusion of chart movement.
Also many thanks to the generous folks at Techsmith for gifting me a copy of their excellent Snagit utility which made the creation and editing of screenshots so easy.