Click here to Skip to main content
13,799,868 members
Rate this:
 
Please Sign up or sign in to vote.
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 22:13pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

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[^].
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

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]
  Permalink  
v2
Comments
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181214.1 | Last Updated 3 May 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100