Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Is there a simple minimal example of a project in Visual C++ that graphs x-y data?

This is to operate a small spectrometer. I would like a starting point that shows a graph and does little else, to which I can add controls, a thread that reads the data sent asynchronously from the instrument over a COM port and some plumbing to update the graph.

This is an urgent need, it is for underfunded schools, and I need a little help to get a quick start.

Thank you

What I have tried:

Searched forums, code repositories
Posted
Updated 28-Jan-24 2:14am
v2
Comments
0x01AA 28-Jan-24 9:06am    
Have a look e.g. here: Chart Control in Windows Forms Application[^]
Simply change the seires type from bar to line in the series property. The example is c#, but it is easy to do the same with c++.

Here something in c++: An easy way to plot in a Visual Studio 2019 C++ program. - Microsoft Q&A[^]
DrMN 28-Jan-24 9:40am    
Thank you, but that is .net. I have no experience with .net, only simple c++ and winapi, but it does look simple. Does it do scientific style graphics? The article shows only an excel style chart.
0x01AA 28-Jan-24 9:45am    
I really suggest to switch to .net. It is very simple to do a WinForm application.
You simply put a graph onto a form and set e.g. the properties for the graph series in the vs designer.
Yes you can do scientific graphics. Most examples shows bar graphs (don't ask me why). But as mentioned, set the property of a series from bar graph to line series and you can easely show yoour spectral graph e.g. from 360-750 nm

Btw. may I ask you which brand/model of spectrophotometer you are using?
DrMN 28-Jan-24 9:56am    
I built it. It is derived from this design https://github.com/drmcnelson/Linear-CCD-with-LTSpice-KiCAD-Firmware-and-Python-Library. The item in question is a little more eloquent, a lower noise front end with a 16 bit diff ADC, and fits inside a handheld size housing.

In case you are interested, this one, with a higher end sensor should be ready soon. I have the boards back from fab. https://github.com/drmcnelson/S11639-01-Linear-CCD-PCB-and-Code
0x01AA 28-Jan-24 10:01am    
Wow! Cool!
If you build this, than a .net winform app would be easy for you ;)

1 solution

You know you may search articles, here at CodeProject.
An example of a quick search[^]
 
Share this answer
 
Comments
DrMN 29-Jan-24 6:30am    
Yes, and yet not one of those at least in the first 10 or so, are just a simple 2-d graph. You have bar charts, multiple axes, and on and on. To use any of that, I have to study the code enough to pick it apart and hope nothing extraneous remains or critical was removed. It is not a good starting point to write a program. I understand, developers want to show off what it can do, but to use it easily, we need a maximally simple example to know where to start. It took a long time before the people at matplotlib got that, too. It is crucial if you want someone to use your software.
CPallini 29-Jan-24 6:52am    
Well, if you are searching for something minimalist then you may have a look at GDI+ documentation:
https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-getting-started-use
There is shown how to use the graphics primitives. Then it is just a matter of scaling and translating points.
DrMN 29-Jan-24 8:38am    
Thank you, that is actually a big help. As you noted those are primitives, rather than a minimal example, but the rest is known art. Great.
DrMN 29-Jan-24 6:32am    
I did actually search before posting the question, and on other forums as well. The animation one seems to have the write words in the title, but again, I haven't found an easy to use example that is relevant for me.
DrMN 29-Jan-24 6:59am    
I looked at the next few pages of them. Wow. One even writes more or less, "it does everything, it is unlimited, but I don't have time to write documentation". The words "memory leaks" appear in the comments. It is really surprisingly difficult to find something that is simple and comes with a simple example that works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900