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 :)
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?
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 :(
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