15,667,475 members
Articles / Programming Languages / C#
Article
Posted 15 Nov 2008

27K views
15 bookmarked

# Graph control

Rate me:
15 Nov 2008GPL3
this controls allows to draw function graph.

## 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<pointf>, Color c, VisualizationType type);
</pointf>```

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>();<pointf><pointf>
for (double x = 0; x < 10; x += 0.1)
{
points.Add(new PointF((float) x, (float) function(x)));
}
ucGraphSolution1.DrawGraph();

}
</pointf> </pointf> ```
Also you can enlarge scale by the mouse selection and decrease scale by the mouse double click. Good luck!

Written By
Software Developer (Senior)
Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

## Comments and Discussions

 First Prev Next
 My vote of 5 Manoj Kumar Choubey16-Mar-12 3:57 Manoj Kumar Choubey 16-Mar-12 3:57
 Nice
 My vote of 1 Biswas, Sumit4-Aug-09 20:51 Biswas, Sumit 4-Aug-09 20:51
 Corrupt Download MoloneyPat15-Nov-08 13:10 MoloneyPat 15-Nov-08 13:10
 Re: Corrupt Download Slezko S.G.15-Nov-08 14:30 Slezko S.G. 15-Nov-08 14:30
 Last Visit: 31-Dec-99 18:00     Last Update: 3-Jun-23 18:18 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.