Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate axis in graph

Status
Not open for further replies.

MagiMike

Technical User
Jun 5, 2003
44
SE
I'm trying to make a Graf-class but I can't come up with a good way to calculate the axis from the values so that the values are always represented in a decent way.
Does anyone know a good way to do it? It doesn't have to be in code, just a concept or so.

thanks
Mike
 
I havn't tried this before but couldn't you just change the graph coordinates in the class code so that it would match the client window? For example, lets ay we would like to add CPoint(1,1) to your cartesian plane with the origin located at CPoint(100,100) on your client window. You would call a CGraph functin like SetPoint(CPoint(1,1)). Then in the class code it would know that (1,1) is really (101,101) on the client window. This can simply be done by CPoint(100,100)+CPoint(1,1). Then if you wanted 1 space to be 5 pixles length or so, that would be easy as well.


Is that what you mean? If not it was interesting anyway lol.

-Bones
 
Thanks, but that's not the real problem.
The problem is finding a suiting scale on the x and y axis from the values that are to be represented.
Like the standard 0-1-2-3-4-5-6-7-8-9-10. But if there's only numbers between 4 and 7 it should change the scale automatically to the best possible and also the precision (to perhaps 0.2).
I wonder if there's a common way to do this or should I write an own algorithm for it?
 
Ah I see. I doubt there is a common way of doing something like this, you will probably be better off writing your own algorithm. (unless someone else here knows of an easy way of going about it) That will be pretty cool if your program changes automatically! (are you making a graphing calculator?) You could probably make the scale size pretty easy by changing a variable like CPoint(int size * x, int size * y); and that would change the scale size. And that was the easy part, I'll let you or someone else find the hard one of setting the precision lol. Good luck, sounds like a neat program. Wow, its also in a class so you could make several different precisions in the same window easily.

Just a couple of ideas...

-Bones
 
Nice idea about putting it in a class. I was just about going to put it in the view class. But it's probably worth a little extra time to make it independent. :)
I'm pretty finished doing an algorithm (on paper)for scale starting at zero. Then I'll only need to apply an offset to make it work with scales starting at a different point.

It'll be like those graphs in excel to analyze data in an MFC window.
Or does anyone know an MFC class that does this for you? I've searched around and I haven't found any GraphCtrl or something like that. Only homemade ones that I really can't figure out how they work, so I'm probably better of doing one on my own.
 
Hi,
I am also having a difficult time coming up with an algorithm for range and precision for the axis of a graph. Any assistance you can offer would help. I am at a road block.
Thayou in advance,
Susan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top