Graph a Set of Values from an Array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Graph a Set of Values from an Array

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    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.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Graph a Set of Values from an Array

    Quote Originally Posted by Peter_B View Post
    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

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: Graph a Set of Values from an Array

    Quote Originally Posted by MikeAThon View Post
    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
    Quote Originally Posted by Opcode View Post
    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.

  5. #5
    Join Date
    Oct 2008
    Posts
    1,088

    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 ...

  6. #6
    Join Date
    Feb 2012
    Location
    Fremont,CA
    Posts
    36

    Re: Graph a Set of Values from an Array

    Sorry I don't know about C++ because I have no more idea about it.
    Make sure you check out my >>Facebook Development Blog and Website<<

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center