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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

770 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