plotting graph in C# (x.y) points

i want to plot a graph in x,y axis like excel in c#

Page 1 of 1

8 Replies - 81228 Views - Last Post: 28 September 2008 - 11:27 AM Rate Topic: -----

#1 lunaahmed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-September 08

plotting graph in C# (x.y) points

Post icon  Posted 24 September 2008 - 01:55 PM

Hi

Pls i need to plot a simple graph from a text file having the coordinate values .

i could not find anything to plot a graph in c#. Is there any graph function?
Is This A Good Question/Topic? 0
  • +

Replies To: plotting graph in C# (x.y) points

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: plotting graph in C# (x.y) points

Posted 24 September 2008 - 03:16 PM

No graphing functions are built into the standard library. You will need to implement your own or use a third party plug-in.
Was This Post Helpful? 1

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: plotting graph in C# (x.y) points

Posted 24 September 2008 - 03:54 PM

What kind of graph? A simple scatter graph?

This gives me an idea...
NEW PROJECT!

I don't think it would be too difficult to design some graphing stuff.

Thanks for the idea! I'll post up something when I'm got started.

Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: plotting graph in C# (x.y) points

Posted 24 September 2008 - 04:15 PM

OK, Here's some basic code that will hopefully get you started.

It draws the x/y axis on to a bitmap in red, and then adds a point at (20,30)

It's messy, but it might get you started:
		public MainForm()
		{
			// just make the window big enough to fit this graph...
			this.Width = 500;
			this.Height = 350;
			
			// add 5 so the bars fit properly
			int x = 240; // the position of the X axis
			int y = 0; // the position of the Y axis
			
			Bitmap bmp = new Bitmap(360, 290);
			Graphics g = Graphics.FromImage(bmp);
			g.DrawLine (new Pen(Color.Red, 2), 5,5, 5,250);
			g.DrawLine (new Pen(Color.Red, 2), 5,250, 300,250);
			// let's draw a coordinate equivalent to (20,30) (20 up, 30 across)
			g.DrawString("X", new Font("Calibri", 12), new SolidBrush(Color.Black), y+30,x-20);
			
			PictureBox display = new PictureBox();
			display.Width = 360;
			display.Height = 290;
			this.Controls.Add(display);
			display.Image = bmp;
		}

Was This Post Helpful? 0
  • +
  • -

#5 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: plotting graph in C# (x.y) points

Posted 25 September 2008 - 05:23 PM

hey quick question.. why use this.MemberVar? Why not just Form.MemberVar?

I see this all of the time, and I don't like it but there must be a purpose.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: plotting graph in C# (x.y) points

Posted 25 September 2008 - 05:44 PM

The this keyword refers to the current instance of the class, in this case referring to the form that is being worked in. If you had a class, say named Employer then this would refer to the instance of the Employer class that is currently instantiated. Like

public Employer(string name, string address) 
{
   this.name = name;
   this.address = address;
}


Was This Post Helpful? 0
  • +
  • -

#7 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: plotting graph in C# (x.y) points

Posted 25 September 2008 - 10:55 PM

View PostPsychoCoder, on 25 Sep, 2008 - 05:44 PM, said:

The this keyword refers to the current instance of the class, in this case referring to the form that is being worked in. If you had a class, say named Employer then this would refer to the instance of the Employer class that is currently instantiated. Like

public Employer(string name, string address) 
{
   this.name = name;
   this.address = address;
}



so this.name and this.address are actually member vars inside of of the class Employee. And the parameter names are name and address.
If my understanding is correct why not just use name = name and address = address (maybe have to change var names on one or the other depending on the scope)

what is the special purpose of this ?
Was This Post Helpful? 0
  • +
  • -

#8 vertizor  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 27-September 08

Re: plotting graph in C# (x.y) points

Posted 27 September 2008 - 09:50 PM

The answer, with regard to what PsychoCoder posted, is that this.name refers to a class-level variable, while "name" in that context is a local variable for that method. Of course, naming the method variables differently would have allowed you to simply use name and address as the class variables, but ... especially when your working on other people's projects, this isn't always an easy option.

Edit - perhaps to be a little more clear ... name, in the context of that method, has only 1 meaning - the parameter variable name. name = name will, in any context, be a tautology of sorts ... assigning a variable's value to itself doesn't accomplish anything.

This post has been edited by vertizor: 27 September 2008 - 10:06 PM

Was This Post Helpful? 1
  • +
  • -

#9 fremgenc  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 119
  • Joined: 15-November 07

Re: plotting graph in C# (x.y) points

Posted 28 September 2008 - 11:27 AM

View Postvertizor, on 27 Sep, 2008 - 09:50 PM, said:

The answer, with regard to what PsychoCoder posted, is that this.name refers to a class-level variable, while "name" in that context is a local variable for that method. Of course, naming the method variables differently would have allowed you to simply use name and address as the class variables, but ... especially when your working on other people's projects, this isn't always an easy option.

Edit - perhaps to be a little more clear ... name, in the context of that method, has only 1 meaning - the parameter variable name. name = name will, in any context, be a tautology of sorts ... assigning a variable's value to itself doesn't accomplish anything.


Alright I get it now. Thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1