Graph diagram in VC++

Posted on 2003-03-22
Medium Priority
Last Modified: 2006-11-17
Hi, I would like to write a Visual C++ program that reads int or float values from a file (e.g. text file) and displays them graphically in a diagram curve with X and Y coordinates.
1. How do I draw the X and Y axis with the respective scale and label them?
2. How do I draw the curve?
Thx for your help!!!
Question by:zaratin

Accepted Solution

cathalcourtney earned 300 total points
ID: 8187518
Easiest thing would be to use MFC. Create a new MFC exe project using the app wizard. single document template, etc.

The app wizard wlil generate a view class and in this class an OnDraw method. In this method you have access to a device context CDC pointer - pDC. You can use this to draw stuff on the screen. Some of the methods you could use are - Arc, Chord, DrawEdge, ....

If you want to use scale the points, use the method GetClientRect in your view class. This will give you the size of the client window so you can scale your graph to this.

The reading of the file should be done in the document class. Use CFile to read the file. You can store this data in member variables and access it from your view class by using GetDocument() function which returns an instance of your Document class.

Hope this helps


Expert Comment

ID: 8187979
Hello Zaratin,

Since I see no reason for inveting the cube again (or was
that "the wheel"?), take a look at different examples
at codeguru, for example this one:




Author Comment

ID: 8203295
Hello Cathal and Ulrik and thanks for the hints...I followed Ulrik's link and found a mighty graph tool.
I would like to use this to visualise my own data that I read from a text or CSV file. Could anyone please tell me how and where to implement the file reading part? I've been trying to do it in test_grafixView.cpp on the New Graph menu item but I get Runtime Error Message "abnormal program termination" unknown software exception (0x80000003) on 0x1020b1f3, but due to lack of experience I can't figure out why. What am I doing wrong?
I use CFile object to read my values into CArchive and a loop to read single values from CArchive into x or y axis values.
The method "graph_wnd.AddPoint(res_graph, x, y)" doesn't seem to work when called inside the file handling loop (above mentioned error).

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

621 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