-
March 30th, 2012, 11:21 PM
#1
Graph a Set of Values from an Array
I am taking a beginner C++ class in junior college using MS Visual Studio 2010. I've never programmed graphics in a windowed environment, and it is not even part of this class. However, my current assignment produces a set of 100 random values (on which I'm supposed to perform some statistical analysis) that I would like to graph, for my own benefit. What would be an easy, quick and free way for me to plot the values from an array of 100 elements onto a graph?
Thank you.
-
March 31st, 2012, 02:49 PM
#2
Re: Graph a Set of Values from an Array
If this is just for your benefit, and is a one-off thing, it would be best to just use a spreadsheet (Excel/OpenOffice etc.). No need to get into programming at all.
-
April 4th, 2012, 04:59 PM
#3
Re: Graph a Set of Values from an Array
Originally Posted by Peter_B
If this is just for your benefit, and is a one-off thing, it would be best to just use a spreadsheet (Excel/OpenOffice etc.). No need to get into programming at all.
Except that the OP is "taking a C++ class using Microsoft Visual Studio", and clearly intends to "get into programming".
To Opcode: Candidly, there is not easy way to get into Windows programming. It's complicated, and unlike the code you are probably writing now (which is procedural code), Windows programming is event-driven (which means that Windows tells your code when it's time to do something, and then your code must respond appropriately).
Moreover, you are probably using the express edition of Visual Studio, which means that you do not have access to some of the simplifying frameworks such as MFC.
If you want to try to learn it yourself (very hard), then you might look for tutorials on the web. In the early days of Windows programming, code was C-style code. The advantage of looking backwards at C-style code is that you might end up with a better understanding of the underlying event-driven concepts. In Googling for tutorials on windows programming, one hit that turned up was http://www.winprog.org/tutorial/ . I do not know if the tutorial is any good, but it illustrtates the C-style of coding. For your purposes, to simplify things, I would include your data as part of the compiled code (or generate it in the code), and then respond to the WM_PAINT message by (1) creating a simple pen and selecting it into the device context (see "Creating Colored Pens and Brushes" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx ), (2) looping on the data and calling MoveToEx to move to an appropriate position in the device context (see "MoveToEx function" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx ), and (3) at each position, drawing a circle (or some such shape) by calling Ellipse (see "Ellipse function" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx ). A helpful example of code for responding to WM_PAINT is found at the afore-mentioned "Creating Colored Pens and Brushes" at http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
I warned you that it was complicated.
There have been many attempts to wrap traditional C-style of coding for Windows into a framework using C++-style classes (MFC, mentioned above, is one attempt from Microsoft). If you would prefer to use C++-style coding, then this tutorial might help: "Windows API Tutorial" at http://www.relisoft.com/win32/index.htm
But the framework doesn't make the underlying concepts any easier to understand.
Good luck,
Mike
-
April 4th, 2012, 05:36 PM
#4
Re: Graph a Set of Values from an Array
Originally Posted by MikeAThon
Except that the OP is "taking a C++ class using Microsoft Visual Studio", and clearly intends to "get into programming".
Yes, Opcode is taking a C++ class, but graphics is not part of this class, and Opcode didn't say that he/she wanted to actually write code to solve this, he/she just asked for a solution which is an
Originally Posted by Opcode
easy, quick and free way for me to plot the values from an array of 100 elements onto a graph?
By your own admission, coding this is not easy, and certainly won't be quick either. Spreadsheets on the other hand, are both, and in the case of OpenOffice, free as well.
-
April 11th, 2012, 08:53 AM
#5
Re: Graph a Set of Values from an Array
take a look at gnuplot, it's widely used in the scientific community to quickly plot data; your program can generate data files or even gnuplot scripts to automate complex plot generation directly from c++ code with simple standard text stream operations ...
-
November 30th, 2012, 12:03 AM
#6
Re: Graph a Set of Values from an Array
Sorry I don't know about C++ because I have no more idea about it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|