• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

graph dispay and labeling using VC++

Given an equation, let say f(x) = 20exp(-2x), how can i display the result of this equation , including labelling  the x and y-axis and the graph titile?
1 Solution
you have to parse the equation first.. there's plenty of code on the net for parsing equations (try Yahoo or AltaVista)... once you have parsed the equation and you have the values you need, you could graph it using Win32 functions such as SetPixel() (which is dog slow) or could use some other functions... it's your choice...

Once you have your equation results, say, the x and the y, use the following functions to draw to, for example, a CDC:

For Labeling the axis:

BOOL TextOut( int x, int y, const CString& str );


int DrawText( const CString& str, LPRECT lpRect, UINT nFormat );

To draw the text VERTICALLY, you will need to employ workaround methods, like draw to a separate memory dc, rotate it and then blit it to the screen's dc, but that's another topic on it's own!!

For Plotting the lines or values:

Depending on how fast the data comes in and how you want it displayed, you could use either of the following methods:

CPoint MoveTo( int x, int y );
BOOL LineTo( int x, int y );

This is probably more desireable. Use these two functions to draw a line from the last point plotted to the new x,y


COLORREF SetPixel( int x, int y, COLORREF crColor );

which is quite slow, but wouldn't be noticeable for most graph usage, IMO.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now