Click here to Skip to main content
6,631,404 members and growing! (19,023 online)
Email Password   helpLost your password?
Languages » C# » Windows Forms License: The GNU General Public License (GPL)

Graph control

By Slezko S.G.

this controls allows to draw function graph.
C# (C# 1.0, C# 2.0, C# 3.0)
Posted:15 Nov 2008
Views:4,293
Bookmarked:11 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
4 votes for this article.
Popularity: 1.08 Rating: 1.80 out of 5
2 votes, 50.0%
1
1 vote, 25.0%
2
1 vote, 25.0%
3

4

5

Introduction   

There are many times when we need simple tool for draw function graph. And the best solution for this task is a control which include all logic for drawing with simple interface for loading data. So, one alternative of such control represens in this article.

Let's begin 

Inerface of this control is very simple. It's include properties for set bounds of drawing box and function to load data for build graphic:

public double MinX;
public double MaxX;
public double MinY;
public double MaxY;

public void AddObject(List<PointF> coords, Color c, VisualizationType type); 

By the function AddObject we can load array of points which will draw with specified color c and can have one of three types visualization: 1) continous line 2) points 3) daggers. We can load many objects for draw at a time. When we finished loading of object we simple call function DrawGraph() and all our objects appear on the screen. For use this control you must add library to your solution and add control from toolBox on your form. Next code show how you can use this control for drawing a graph:  

        private double function (double x)
        {
            double res = Math.Sin(x);
            return res;
            
        }
        private void btnDraw_Click(object sender, EventArgs e)
        {
            List<PointF> points = new List<PointF>();
            for (double x = 0; x < 10; x += 0.1)
            {
                points.Add(new PointF((float) x, (float) function(x)));
            }
            ucGraphSolution1.AddObject(points, Color.Red,VisualizationType.DAGGERS);
            ucGraphSolution1.DrawGraph();
            
        }
  
Also you can enlarge scale by the mouse selection and decrease scale by the mouse double click. Good luck!

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

Slezko S.G.


Member

Occupation: Software Developer (Senior)
Location: Russian Federation Russian Federation

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberBiswas, Sumit21:51 4 Aug '09  
GeneralCorrupt Download PinmemberMoloneyPat14:10 15 Nov '08  
GeneralRe: Corrupt Download PinmemberCerg15:30 15 Nov '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Nov 2008
Editor:
Copyright 2008 by Slezko S.G.
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project