Solved

Draw graphs.

Posted on 1998-09-01
7
479 Views
Last Modified: 2008-02-20
i have currently developed a sdi program for my sch's project. the window has two panes which i have derived from the CFormView and CView.

the users will enter some parameters in the CFormView, they will be processed by some equations. the question is... how do i draw a graph wif x and y axis on the CView so that when the user enter the parameters (from the CFormView), the results can be shown on the CView with a graph. the graph is not unlike a sin/cos curve.
0
Comment
Question by:bi7206327
  • 3
  • 3
7 Comments
 

Author Comment

by:bi7206327
ID: 1171856
Edited text of question
0
 

Author Comment

by:bi7206327
ID: 1171857
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1171858
1. You need to share the data between the 2 views.  The best place to do this in your CDocument derived class.

i. Add data members to the document
ii. In CFormView set the data at appropriate points into the document using

((CMyDoc *)GetDocument())->m_nValue = /* value from CFormView */

If you change the GetDocument() definition to return your doc class in CFormView you can avoid the nasty cast.

2. When the graph needs to be repaint (say the user hit the Refresh button in the CFormView) you can force a repaint using GetDocument()->UpdateAllViews()

3. In CView you add the drawing code.  Override OnDraw and adding painting code here.  You can get the data out the document using the reverse of the code I gave in step #1.  Use functions like LineTo, MoveToEx, TextOut (members of CDC and you get a pointer to one of these in OnDraw) to draw the stuff.

4. Drawing graphs with all the correct axes, labels, and so forth is a lot of work.  You may wish to consider using a commercial toolkit (which will save you writing most of the graph drawing code).

The two best known (to me <g>) are

i. Graphics Server by Bits Per Second
http://www.bitspersecond.co.uk/gs_reviews.asp

ii. Olectra Chart
http://www.klg.com/welcome.html

You can find a comparison at
http://www.hallogram.com/compare/graphs.html

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:Answers2000
ID: 1171859
You're editted text came thru while I was typing, so commercial toolkits may be out the question ?  

If you need more help on #3 and #4 then let me know what you need.  

The coordinate system by default has 0,0 at the top left and is in pixels.

I've got to go offline for a bit, but I'll be back later, so post any comments on what else you might need.
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1171860
In the form view catch when the user makes any changes to the children controls. One good technique for this is to create handler for notification messages of the children controls. For example you might catch EN_CHANGE or EN_KILLFOCUS for an edit control, or BN_CLICKED for a check box and so on. Then in these handlers call the UpdateData(TRUE) method of the CFormView. Link your controls to corresponding data members of your document class. You can do that by using DDX mechanism in your CFormView's DoDataExchange(). The easiest way to link them is to create member variables for the controls in the class wizard, and then in the DoDataExchange() replace those variables with your document variables. Be sure however to move the changed code outside of the class wizard comments. Otherwise the class wizord will not work the next time you start it.
Finally after calling UpdateData(TRUE) in your handlers call UpdateAllViews() method of your document. This will ensure that the document (assuming it is the document of the CView) will call the CView's OnUpdate() and will repaint your other view.
Basically that's the MFC way of one view to react to changes of another view.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1171861
Milenvk makes a good point.  The only caveat is that if regenerating the graph takes a long time you may prefer to either
(i) have a manual update/refresh button
or
(ii) Setup a timer (SetTimer funciton) in the FormView, add a boolean member to it to (initially set to FALSE), and whenever one of milenvk's changes happen set the flag to TRUE.  In the TimerProc look for a true flag, and only in this case redraw the graph (and then reset the flag back to false).  This way you don't have to have a long pause immediately after the user types in each digit into say a numeric field.

0
 

Author Comment

by:bi7206327
ID: 1171862
commercial toolkits are out of the question bcos my school project does not have a budget for it (such toolkits cost money rite??)

pls forgive me for i have just started learning VC++.... so can you kindly explain in more details the following:

1) Drawing of grids using the LineTo, TextOut etc etc functions.

2) For the program to generate the graph... let say i got two variables, theta and displacement, i will calculate the displacement at certain interval of theta. eg, at theta equal to 5, 10, 15, 20.... displacements are d1, d2, d3, d4. as such i would have the various pts. question is, how do i map this points into the grid i have drawn?? also, how to i join this various pts up after i mapped them into the grid i drawn??

the project gonna due very soon and i just can't seem to solve the problem. your help is very much appreciated. thanz in advance.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now