how does the plot function work?

i need to plot a graph using the plot function in a console application which i have never used before.
Could someone maybe put up sample code so i know how the function works because i dont even know where to start.

I have to make a graph this way i can't use GUI or some graph making package so if anyone can help i would really appreciate it

thanks

There's a plot function?!
according to my lecturer there is...
we were told to use for loops and a plot function
is there functions for graphs??
I think you were prob being told to write a plot function which uses loops. As Gaminic said, there is no (standard) plot function.
It's also possible that they're using some non-standard libraries in their work. Plotting something in the console seems rather... cheap, if you don't mind me saying. :)

Are you perhaps using chplot?
http://www.stat.umn.edu/macanova/htmlhelp/node50.htm

-Albatross
Last edited on
While it's possible, I think it's pretty unlikely. Using the console to display graphs does seem to be a pretty common beginner's exercise. I've seen assorted threads on the same subject on this forum, and even helped out/tried to help out on a couple of occasions.
Last edited on
so if there is no standard plot function how do you make a graph using loops?
@kw1991

Maybe this can help. I used a function called gotoXY(x,y); to print at specific locations on screen.
http://cplusplus.com/forum/general/49976/
@whitenite1
thank you that was exactly what i was looking for.
quick question though: how do i make a continuous line instead of the $ symbol used in your example?
A horizontal line can be done by using "_" instead of "$", however you will not be able to make any other kind of line continuous in the console. For that you'd have to develop some sort of GUI which is not a simple task.
ok then i'll just used the dashed line
thanks
and is it possible to make a vertical line for the y axis with numbers on the side?
in whitenite1 example there was only a horizontal line
Last edited on
@kw1991

Is this what you were asking for? If you're wanting a line chart, a line connecting point x[a],y[b] to the next point, I have no idea.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main(int)
{
	int x[] = {0,3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60};
	int y[] = {5,7,11,14,11,10, 9,11, 9,10,10,7,11,10, 9, 12,14,12, 7, 8,15};
	int a,b;
	string line(80,'_');
	string XValue = "X Value";
	int bottom = 15;
	gotoXY(27,20,"Y value");
	for (a=0;a<7;a++)
	{
		gotoXY(1,7+a);
		cout << XValue[a];
	}
	for ( a = 0; a < 20; a++)
	{
		int X=y[a];
		do
		{
			gotoXY(3+x[a],X,"\xDB");
			X++;
		} while (X != bottom);
		gotoXY(3+x[a],16);
		cout << a+1;
		gotoXY(3+x[a],18);
		cout << y[a];
	}
	gotoXY(0,15,line);
	gotoXY(0,25);
	WaitKey();
	return 0;
}


EDIT: Added the YValues at bottom, and the word 'X Value' on side.
Last edited on
@kw1991

Hopefully, this is what you meant, then. [ fingers crossed ;) ] If you need a different numbering system, change the numbers in the loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
int main(int)
{
	int x[] = {0,3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60};
	int y[] = {5,6,7,14,11,10, 9,11, 9,10,10,7,11,10, 9, 12,14,12, 7, 8,15};
	int a,b;
	string line(80,'_');
	int bottom = 15;
	
	for (a=15;a>0;a--)
	{
		gotoXY(0,a);
		if (14-a <=9)
			cout << " ";
		cout << 14 - a<< "__";
	}
	for ( a = 0; a < 20; a++)
	{
		int X=y[a];
		do
		{
			gotoXY(5+x[a],X,"\xDB");
			X++;
		} while (X != bottom);
		gotoXY(5+x[a],16);
		cout << a+1;
		gotoXY(5+x[a],18);
		cout << bottom-y[a];
	}
	gotoXY(0,15,line);
	gotoXY(0,25);
	WaitKey();
	return 0;
}
Last edited on
yes the numbers are on the side now thanks.
is it possible to make a continous line next to those numbers like the line at the bottom of the graph?
Last edited on
Yes it is, I'll post it a little later today. I'm in the process of making dinner.
no problem. thanks for all the help
@kw1991

You'll have to adjust this to suit your program, but I don't think it'll be to hard. If you have a problem with it, drop another line here, and I'll see what can be done.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main(int)
{
	
	int y[] = {5,6, 7,3,11,10, 9,11, 9,10,3,7,11,10, 9, 12,5,12, 7, 8,10};
	int a,b;
	string line(65,'_');
	int bottom = 15;
	
	for (a=0;a<12;a++)
	{
		gotoXY(1,2+a);
		{
			cout << 11-a << line << 11-a ;
		}
	}
	
	for ( a = 0; a < 20; a++)
	{
		int X=14-y[a];
		do
		{
			gotoXY(5+(3*a),X,"\xDB");
			X++;
		} while (X != bottom);
		gotoXY(5+(3*a),16);
		cout << a+1;
	}
	gotoXY(3,14,line);
	gotoXY(0,25);
	WaitKey();
	return 0;
}
Topic archived. No new replies allowed.