Making Line Graphs
Hi, this isn''t really a game programming question. However, it does have something to do with graphics.
Anywho, I''m having trouble with a program I''m currently developing. My problem is I have a table of values basically and I''m trying to construct a line graph. Something like this:
(These are the ones on the Y axis I want to plot)
102
130
236
32
76
260
...ect
I''m having trouble with determining the scale factor, or Y axis increment.. or whatever you''d like to call it.
Basically how much each pixel represents on the Y axis. Get it?
/
/
/ <-- increment for this axis...
/
/--------
0 1 2 3 4
I can''t seem to figure this part out. Any help is appreciated.
Thanks,
Shaun Patterson
Why don''t you try dividing the graph''s height (in pixels, say 200) by the maximum y-value you need to plot (in the list you posted, 260). That''s about 0.769 pixels per Y unit. Then multiply the Y-value to plot by 0.769 and plot it on the screen. (e.g. one of the values you''ve given is 102. Multiplied by 0.769 that''s 78 pixels.) Plot every point or line at the correct point above the x-axis to draw your graph.
I hope this helps.
Mark T.
I hope this helps.
Mark T.
well, the problem is that you want to work with 2 coordinate systems: one with the origin in the upper left, and one with the origin in the lower left, along with the fact that 102, 130, etc., might not be the number of pixels,but another unit of measurement, but ill leave that up to others
as for the origin flip, just do (SCREEN_HEIGHT-y) to plot a y with lower left being the origin
Edited by - Zipster on 4/1/00 5:32:14 PM
as for the origin flip, just do (SCREEN_HEIGHT-y) to plot a y with lower left being the origin
Edited by - Zipster on 4/1/00 5:32:14 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement