Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 18th, 2006, 10:06 AM
Registered User
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Drawing a graph from an ArrayList

I've recently purchased 'Beginning VC# 2005' but whilst it's very good in most areas it doesn't take me far enough in GDI+.

I need to draw a graph based on objects in an ArrayList which effectively give me the points on my graph.

The completed graph will need to be considerably longer than the screen is wide.

I've managed to get the mechanics working using the following code :-
        protected void PlotGraph(ArrayList eventList)
            DateTime start, next;
            TimeSpan duration;
            int length, xpenposn1, ypenposn1;
            int xpenposn2 = 50, ypenposn2 = 550;
            int nextLabour, labour, height;
            Graphics g = this.pictureBox1.CreateGraphics();
            using (Pen bluePen = new Pen(Color.Blue, 2))
                for (int k = 0; k < eventList.Count - 1; k++ )
                    start = ((Event)eventList[k]).EventTime;
                    labour = ((Event)eventList[k]).TotalLabour;
                    next = ((Event)eventList[k+1]).EventTime;
                    nextLabour = ((Event)eventList[k+1]).TotalLabour;
                    height = 5 * (nextLabour - labour);
                    duration = next - start;
                    length = 3 * duration.Hours + 60*duration.Days;
                    xpenposn1 = xpenposn2;
                    xpenposn2 = xpenposn1 + length;
                    ypenposn1 = ypenposn2;
                    g.DrawLine(bluePen, new Point(xpenposn1, ypenposn1), new Point(xpenposn2, ypenposn2));
                    xpenposn1 = xpenposn2;
                    ypenposn1 = ypenposn2;
                    ypenposn2 = ypenposn2 - height;
                    g.DrawLine(bluePen, new Point(xpenposn1, ypenposn1), new Point(xpenposn2, ypenposn2));

Of course when I scroll across to look at the hidden portion of the graph it disappears. I recognise that I need to OnPaint method but I can't quite see how.

Thanks for any help.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing Shapes cbulutlar Javascript 2 March 6th, 2006 02:25 PM
drawing fergo Access VBA 0 June 6th, 2005 12:35 PM
drawing fergo BOOK: Access 2003 VBA Programmer's Reference 1 June 5th, 2005 09:32 AM
Drawing in C# stripytiger VS.NET 2002/2003 4 August 25th, 2004 10:01 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.