Article Options
Recently Viewed
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  GDI+ Chart Success Part 6: Dynamic Line Chart  »  Summary
 »  Home  »  Windows Development  »  Graphics  »  GDI+ Chart Success Part 6: Dynamic Line Chart  »  Summary
 »  Home  »  Windows Development  »  Win Forms  »  GDI+ Chart Success Part 6: Dynamic Line Chart  »  Summary
GDI+ Chart Success Part 6: Dynamic Line Chart
by Ged Mead | Published  08/22/2006 | .NET Newbie Graphics Win Forms | 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...
Summary

Possible Enhancements

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!

Topics Covered


In this article, we covered the following topics:

  • Brushes
  • Dispose method
  • Double Buffering
  • DrawLine method
  • DrawImage method
  • DrawString
  • FillPolygon method
  • Font object
  • Format menu item
  • Graphics.FromImage method
  • Pens
  • Scaling
  • TranslateTransform method

 

Demonstration Sample Solution

All the code described is included in the attached sample solution, which was created using  VB.NET 2003. 

Series Summary

 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.

Enjoy!

___________________________________________________________________________________


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.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:3.25352112676058 out of 5
 142 people have rated this page
Article Score34496
Article Series
This article is part 2 of a 3 part series. Other articles in this series are shown below:
  1. Chart Success Part 5 - Line Graph
  2. GDI+ Chart Success Part 6: Dynamic Line Chart
  3. GDI+ Chart Success Part 7: Printing Charts
Related Articles
Attachments
Comments    Submit Comment

Comment #1  (Posted by Mark Prichard on 08/24/2006)
Rating
I appreciate this series very much. Within minutes of finding your articles I had adapted the ideas to work in my personal project, and had a working graph.Thanks for taking the time to create this series.
 
Comment #2  (Posted by Robert Gillespie on 09/05/2006)
Rating
This is great. From knowing nothing about graphs I can now do graphs. Only one question. How would you print the graph.
 
Comment #3  (Posted by Ged Mead on 09/19/2006)
Rating
It looks as though there's going to have to be a Part 7 after all :-} I will publish a follow up showing how to print graphs, hopefully some time in the next few weeks.
In the meantime, Robert, I will email you some outline guidance.
 
Comment #4  (Posted by an unknown user on 09/28/2006)
Rating
Excellent article.
 
Comment #5  (Posted by FERNANDO HOOD on 01/06/2007)
Rating
Excellent document however the function keeps failing at

If Not IsNothing(PicBox.Image) Then
gr.DrawImage(PicBox.Image, -XMove, 0)
End If

System.InvalidOperationException was unhandled
Message="Object is currently in use elsewhere."
Source="System.Drawing"
StackTrace:
at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
at System.Windows.Forms.PictureBox.get_ImageRectangle()
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at MaxiCOM.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()





 
Comment #6  (Posted by an unknown user on 01/10/2007)
Rating
How do I deal with a situation where the data for the graph is handle brought in b a subroutine running on it own thread e.g the serial port?
 
Comment #7  (Posted by an unknown user on 01/27/2007)
Rating
One of the best articles I have seen on charting. Very focused and "to the point" descriptions. Concentrates on the task at hand than introducing unnecessary programming complexities.
 
Comment #8  (Posted by an unknown user on 11/28/2007)
Rating
Great series!
 
Comment #9  (Posted by an unknown user on 09/01/2008)
Rating
This is Great!
 
Comment #10  (Posted by an unknown user on 06/12/2009)
Rating
This article teach me lot of things;
.. It is mind Blowing
 
Comment #11  (Posted by on 10/11/2009)
Rating

 
Comment #12  (Posted by As a narcotic analgesic, Tramadol can be abused. on 11/07/2009)
Rating
plavix libido plavix libido plavix libido . plavix libido plavix libido . plavix libido plavix libido . plavix libido uk carisoprodol supplier uk carisoprodol supplier . uk carisoprodol supplier uk carisoprodol supplier . uk carisoprodol supplier uk carisoprodol supplier . uk carisoprodol supplier uk carisoprodol supplier uk carisoprodol supplier . generic ambien soft tab generic ambien soft tab generic ambien soft tab generic ambien soft tab generic ambien soft tab . generic ambien soft tab generic ambien soft tab generic ambien soft tab generic ambien soft tab generic ambien soft tab .
 
Comment #13  (Posted by an unknown user on 11/12/2009)
Rating
First class intro for novices!!
 
Comment #14  (Posted by water-soluble and they are renally excreted. on 11/25/2009)
Rating
The mission of the your site.: URLsWithNothing
 
Comment #15  (Posted by Dsfgrg on 11/27/2009)
Rating
The more you know about site: URLsWithURL
 
Comment #16  (Posted by Silvia on 02/18/2010)
Rating
b6KspU I am always excited to visit this blog in the evenings.Please churning hold the contents. It is very entertaining.
 
Comment #17  (Posted by Dave on 03/02/2010)
Rating
Excellent, this really helped me out and was really well explained...
 
Comment #18  (Posted by Dave on 03/02/2010)
Rating
Where can I find the rest of the series please?
 
Comment #19  (Posted by Dave on 03/02/2010)
Rating
Where can I find the rest of the series please?
 
Comment #20  (Posted by Raja on 05/08/2010)
Rating
Hi, where can i find the source code file attachment..
 
Comment #21  (Posted by Silvia on 09/22/2010)
Rating
I am always excited to visit this blog in the evenings.Please churning hold the contents. It is very entertaining.
 
Comment #22  (Posted by OEM software download on 09/23/2011)
Rating
IY2n62 See it for the first time!!...
 
Comment #23  (Posted by Download oem software on 09/29/2011)
Rating
f5zrly Yet, much is unclear. Could you describe in more details!...
 
Comment #24  (Posted by OEM software online on 10/28/2011)
Rating
1EW5oN Good day! I do not see the conditions of using the information. May I copy the text from here on my site if you leave a link to this page?!...
 
Comment #25  (Posted by OEM software download on 10/29/2011)
Rating
L4taoF Uh, well, explain me a please, I am not quite in the subject, how can it be?!...
 
Comment #26  (Posted by OEM software download on 11/05/2011)
Rating
j6m42O Author, keep doing in the same way..!!
 
Comment #27  (Posted by Buy software on 11/05/2011)
Rating
W1ooml The Author is crazy..!!
 
Comment #28  (Posted by Buy OEM software online on 11/06/2011)
Rating
EkMIAP Received the letter. I agree to exchange the articles..
 
Comment #29  (Posted by Buy OEM software online on 11/09/2011)
Rating
bPDvcL Good! Wish everybody wrote so:DD
 
Comment #30  (Posted by Buy cheap Microsoft Office software online on 12/27/2011)
Rating
R7jaTU Sometimes I also see something like this, but earlier I didn`t pay much attention to this!....
 
Comment #31  (Posted by Buy cheap software online on 12/27/2011)
Rating
rwi0w4 Yeah, it is clear now !... Just can not figure out how often do you update your blog?!....
 
Comment #32  (Posted by Cheap oem software on 12/27/2011)
Rating
VmvnJu It`s really useful! Looking through the Internet you can mostly observe watered down information, something like bla bla bla, but not here to my deep surprise. It makes me happy..!!
 
Comment #33  (Posted by microsoft OEM software online on 12/27/2011)
Rating
JAyA5Z Informative, but not convincing. Something is missing but what I can not understand. But I will say frankly: bright and benevolent thoughts!....
 
Comment #34  (Posted by Microsoft Office oem software on 12/27/2011)
Rating
Z2TtA3 I would add something else, of course, but in fact almost everything is mentioned!....
 
Comment #35  (Posted by buy discount oem software on 01/11/2012)
Rating
M9Ra4g comment1
 
Comment #36  (Posted by oem software on 01/11/2012)
Rating
zUPqvC comment1
 
Comment #37  (Posted by discount oem software on 01/11/2012)
Rating
LAu1H7 comment4
 
Comment #38  (Posted by cheap oem software on 01/11/2012)
Rating
o1GK67 comment2
 
Comment #39  (Posted by cheap oem software on 01/11/2012)
Rating
FLZD9Z comment4
 
Comment #40  (Posted by buy oem software online on 01/13/2012)
Rating
gZv33C comment4
 
Comment #41  (Posted by cheap oem software on 01/13/2012)
Rating
4ugZv3 comment6
 
Comment #42  (Posted by oem software on 01/13/2012)
Rating
siGE9X comment4
 
Comment #43  (Posted by oem software online on 01/13/2012)
Rating
9fzFId comment2
 
Comment #44  (Posted by discount oem software on 01/13/2012)
Rating
6H06k2 comment2
 
Comment #45  (Posted by oem software on 02/07/2012)
Rating
RbZEKa See it for the first time!!....
 
Comment #46  (Posted by oem software on 02/07/2012)
Rating
1ESamS Fresh thoughts, fresh view on the subject..!!
 
Comment #47  (Posted by buy cheap oem software on 02/10/2012)
Rating
9XsxK3 Fresh thoughts, fresh view on the subject..!!
 
Comment #48  (Posted by buy cheap oem software on 02/10/2012)
Rating
1r4mtw I do`t see a feedback or the other coordinates from the blog administration!....
 
Comment #49  (Posted by Buy oem Software on 02/11/2012)
Rating
78qKtI Last a few years has been to Ibiza, so met a person there whose style of presentation is very similar to yours. But, unfortunately, that person is too far from the Internet!....
 
Comment #50  (Posted by Buy oem Software on 02/12/2012)
Rating
q73Ta1 Yeah !... life is like riding a bicycle. You will not fall unless you stop pedaling!!....
 
Comment #51  (Posted by college basketball on 02/26/2012)
Rating
jlzqxq Uh, well, explain me a please, I am not quite in the subject, how can it be?!...
 
Comment #52  (Posted by basketball gambling on 02/26/2012)
Rating
cKt0JX Yeah, it is clear now !... From the very beginning I did not understand where was the connection with the title !!...
 
Comment #53  (Posted by nba basketball on 02/26/2012)
Rating
HRHBr3 Yeah? I read and I understand that I do not understand anything what it is about:D
 
Comment #54  (Posted by basketball betting on 02/26/2012)
Rating
spVaew Thanks for all the answers:) In fact, learned a lot of new information. Dut I just didn`t figure out what is what till the end!...
 
Comment #55  (Posted by nba basketball on 02/26/2012)
Rating
lri5IC Thanks, useful material I added your blog to my bookmarks!...
 
Comment #56  (Posted by Discount OEM Software on 03/07/2012)
Rating
FsW5jB I appreciate you sharing this post.Really looking forward to read more. Will read on...
 
Comment #57  (Posted by Adobe OEM Software on 03/07/2012)
Rating
vMeKUc Really informative article post.Really looking forward to read more. Really Great.
 
Comment #58  (Posted by Buy Cheap OEM Software on 03/08/2012)
Rating
gkv93I Really informative blog article.Really looking forward to read more. Want more.
 
Comment #59  (Posted by Microsoft OEM Software on 03/08/2012)
Rating
LZTKyH Enjoyed every bit of your blog. Much obliged.
 
Comment #60  (Posted by wholesale men clothing on 03/20/2012)
Rating
Enjoyed every bit of your article post. Great.
 
Comment #61  (Posted by Reviews of LifeCell on 04/04/2012)
Rating
Very neat article.Really looking forward to read more. Really Great.
 
Comment #62  (Posted by Reviews of LifeCell on 04/04/2012)
Rating
Im grateful for the post.Really thank you! Cool.
 
Comment #63  (Posted by LifeCell Reviews on 04/04/2012)
Rating
I truly appreciate this blog post.Really thank you! Keep writing.
 
Comment #64  (Posted by LifeCell Reviews on 04/04/2012)
Rating
Major thankies for the article. Keep writing.
 
Comment #65  (Posted by Reviews of LifeCell on 04/04/2012)
Rating
Im obliged for the article post.Much thanks again. Awesome.
 
Comment #66  (Posted by RFP on 04/05/2012)
Rating
j2cK7a Fantastic blog.Thanks Again. Awesome.
 
Comment #67  (Posted by Suppliers on 04/05/2012)
Rating
kMdFol A round of applause for your blog post. Really Great.
 
Comment #68  (Posted by Request for Quotation on 04/05/2012)
Rating
xL0Jgs I loved your blog article. Fantastic.
 
Comment #69  (Posted by Buyers on 04/05/2012)
Rating
grv1vW Fantastic blog.Much thanks again. Really Great.
 
Comment #70  (Posted by RFQ on 04/05/2012)
Rating
3T231r Really enjoyed this post.Much thanks again. Really Cool.
 
Comment #71  (Posted by notebook review on 04/13/2012)
Rating
Major thankies for the article.Thanks Again. Awesome.
 
Comment #72  (Posted by notebook review on 04/13/2012)
Rating
Really informative blog post. Great.
 
Comment #73  (Posted by notebook review on 04/13/2012)
Rating
Enjoyed every bit of your post.Really looking forward to read more. Keep writing.
 
Comment #74  (Posted by laptop notebook on 04/13/2012)
Rating
Thanks so much for the post.Thanks Again. Really Cool.
 
Comment #75  (Posted by laptop review on 04/14/2012)
Rating
fDO93I Thanks for the blog post.Thanks Again. Fantastic.
 
Comment #76  (Posted by laptop review on 04/14/2012)
Rating
WAt7if I cannot thank you enough for the article post. Will read on...
 
Comment #77  (Posted by laptop review on 04/14/2012)
Rating
dMSzMU Enjoyed every bit of your article post.Much thanks again. Really Great.
 
Comment #78  (Posted by laptop notebook on 04/14/2012)
Rating
DWDfvb Awesome blog post.Really thank you! Keep writing.
 
Comment #79  (Posted by laptop notebook on 04/14/2012)
Rating
GOfIkD I loved your article.Thanks Again.
 
Comment #80  (Posted by logo design on 04/18/2012)
Rating
4lLDeF Thanks again for the article.Really thank you! Much obliged.
 
Comment #81  (Posted by Bristol Airport Hotels on 04/18/2012)
Rating
sT2IIi Really informative article.Thanks Again. Really Cool.
 
Comment #82  (Posted by Bristol Airport Hotels on 04/18/2012)
Rating
EiAK29 Looking forward to reading more. Great blog article.Much thanks again. Awesome.
 
Comment #83  (Posted by seo on 05/07/2012)
Rating
Im grateful for the article. Will read on...
 
Comment #84  (Posted by social on 05/07/2012)
Rating
Thanks for the post.Much thanks again. Really Great.
 
Comment #85  (Posted by social on 05/07/2012)
Rating
I really liked your blog post.Much thanks again. Awesome.
 
Comment #86  (Posted by bookmarking on 05/07/2012)
Rating
I really enjoy the post.Much thanks again. Great.
 
Comment #87  (Posted by cheap on 05/07/2012)
Rating
This is one awesome post.Really looking forward to read more. Want more.
 
Comment #88  (Posted by serivce on 05/08/2012)
Rating
I really enjoy the blog.Much thanks again. Want more.
 
Comment #89  (Posted by bookmarking on 05/09/2012)
Rating
VCIiMP Enjoyed every bit of your blog.Much thanks again. Cool.
 
Comment #90  (Posted by services on 05/09/2012)
Rating
fmx2VH Major thanks for the blog. Really Cool.
 
Comment #91  (Posted by bookmarking on 05/10/2012)
Rating
DSDuuc Major thanks for the post. Awesome.
 
Comment #92  (Posted by bookmarking on 05/10/2012)
Rating
1sljxG I appreciate you sharing this post. Will read on...
 
Comment #93  (Posted by service on 05/10/2012)
Rating
Byy3PW Fantastic post. Want more.
 
Comment #94  (Posted by bookmarking on 05/10/2012)
Rating
zaEmWL I really like and appreciate your blog. Want more.
 
Sponsored Links