13,703,000 members
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....
Posted 1-May-13 21:13pm

## Solution 1

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[^].

## Solution 2

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[^].

[Update]
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]);
```

[/Update]
v2
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?

Top Experts
Last 24hrsThis month
 OriginalGriff 344 Maciej Los 190 Rick York 85 Richard Deeming 53 F-ES Sitecore 50
 OriginalGriff 5,844 Patrice T 1,697 Richard MacCutchan 1,503 Maciej Los 1,384 Richard Deeming 786