-
October 30th, 2009, 09:03 AM
#1
Basic Graph / Chart in C++
Hello,
I am working on a project, and for a section of this I would greatly benefit from displaying a few points on a graph.
I was hoping someone could maybe show me the (simplest*) way to generating a graph, it will be set as follows.
y axis = 1 to 10
x axis = 0 to 5
I would greatly appreciate any support.
Thank you in advance
-
October 30th, 2009, 10:51 AM
#2
Re: Basic Graph / Chart in C++
Mr Unix*, are you writing a program for Windows or MVS, or ... Unix?
Are you using a console window, a telnet window? Do you have access to a graphical interface?
Will it be good enough if each dot of your graph would be a character, or does it has to be a pixel?
-
November 2nd, 2009, 10:00 AM
#3
Re: Basic Graph / Chart in C++
Hello,
Apologies for my unclear question,
I got this project within a windows environment ='[
I also have access to "wxWidgets", "c", "c++". within this project.
The dot on the graph could be a character yes, I just dont feel its nescessary to download any add-ons for this seeing as its such a basic and small layout.
im was thinking of using wxPen to draw up the lines on a wxWindow/wxFrame or whatever is the easiest.
Any tips would be very much appreciated.
I really have no experience with graphics
Last edited by Unix*; November 2nd, 2009 at 10:40 AM.
-
November 2nd, 2009, 12:19 PM
#4
Re: Basic Graph / Chart in C++
I'm not familiar with wxWidgets, so I don't know if there is something you can easily reuse. Searching a bit with google wouldn't be a waste of time, however.
If you want to draw the graph yourself, that's actually not too involved as long as you don't need to make it very fancy. How to draw the graph depends a bit on what type of graph you want. If you have a linear graph, the just draw a single line. If you have points that should be linearly interpolated, then draw a line between each set of points. If you have another type of graph, then you'll probably want to follow the following approach:
Code:
for each horizontal pixel index
calculate X value corresponding to pixel index
calculate Y value corresponding to X value in graph
calculate vertical pixel index corresponding to Y value
draw line from previous pixel to this pixel
end for
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|