Click here to Skip to main content
15,846,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone..!!

Can anyone please tell me how to draw a line graph on a dialog box in MFC.
I have an array with some values and I need to generate a graph using those values. Which MFC Tool / Class should I use? I have never worked on graphs before so please people help me out....

I am not sure if there is a simple MFC class to do this. You can do it with a Static Control[^] in your dialog that has the SS_OWNERDRAW property. You can then add your lines in the handler for the WM_DRAWITEM message[^].
Share this answer
You may draw yourself (in OnPaint handler) using graphic primitives (GDI or GDI+) or you may use a chart control, like, for instance, Cedric's High-speed Charting Control[^].

Suppose you have an array of coordinates and want to create a linear graph.
First you have to find xmin, xmax, ymin, ymax in order to scale (and translate) all the coordinates to fit into the screen rectangle you intend to use:
x[i] = rcx + rcwidth/(xmax-xmin)* x[i];
y[i] = rcy - rcheight/(ymax-ymin)* y[i];

where rcx, rcy are the coordinates of the top-left point of the screen rectangle and rcwidth,rcheight are its dimensions.
Finally you have to draw all the lines connecting successive points, e.g.
MoveToEx(hdc, x[0], y[0]);
for(n=1; n<N; ++n)
  LineTo(hdc, x[n], y[n]);

Share this answer
Fresher16 3-May-13 3:29am    
How to create a graph? I mean I have never done it before and I am new to MFC. can you help me out?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900