General Development

Line Chart in Vis Studio (non .NET)? – graceworks

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Hey,

I could use some help - does someone know a library or sample code that already generates a line chart in Visual Studio? I have some C code that is collecting a data stream over USB that I need to show in a line chart, near real-time.

Thanks in advance for your help!
God bless,
Tim

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
So you need it to pop up a window or something, initialize your data stream, then poll for new data, and when you get data, display it in a line graph in semi-real-time?

You need it written in C? Or is C++ okay?

Just trying to clarify specs -- I haven't done much of any C++ programming with Windows forms, so it's not like I can just whip something like this up (though I wish I could).

--clint

Edit: A few minutes searching turned up this example on Planet Source Code (my long-time favorite code example site). I'm hoping it's simple enough to just get you started with some of the basics. It was done in DevC++, but I don't know why it couldn't be loaded and used in Visual Studio. Hope that helps!

[This message has been edited by HanClinto (edited June 19, 2007).]

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Good questions - C or C++ is fine. Visual Studio is the tool I have.

Yes, just show the data in line chart (technically the old style chart recorder is more accurate at what I'm wanting). Don't care what window it is in.

Yes, something like statplot would be great but it, along with the others I found, don't do line charts. Odd.

If I knew NI's Labview better, I could probably get by with that. I know HP's (Agilent's) VEE but the last time I tried installing it, it wouldn't install! Well, either of these would have to be able to interface to the C code or to the device directly ... Hmmm.

Thanks for checking.

Anyone done this before?

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
A quick search at codeproject.com revealed these goodies:

In C#:
http://www.codeproject.com/cs/miscctrl/GraphComponents.asp
http://www.codeproject.com/cs/miscctrl/Graphi.asp
http://www.codeproject.com/csharp/zedgraph.asp
http://www.codeproject.com/cs/miscctrl/GraphBox.asp
http://www.codeproject.com/cs/miscctrl/C2DPushGraph.asp
http://www.codeproject.com/cs/miscctrl/ChartControl.asp
http://www.codeproject.com/useritems/DataPlotter_2007.asp

In C++:
http://www.codeproject.com/miscctrl/C2DPushGraph.asp
http://www.codeproject.com/dialog/CStatusGraphCtrl.asp
http://www.codeproject.com/atl/ATLChartControl.asp
http://www.codeproject.com/miscctrl/High-speedCharting.asp
http://www.codeproject.com/miscctrl/pgllib.asp
http://www.codeproject.com/miscctrl/CBarChart.asp
http://www.codeproject.com/miscctrl/xgraph.asp

Also, Dundas Charts is well-known for amazing charting, but it's big bucks.

------------------
Brian

"OOP programmers have a lot of class"

Check out this webhost! Fantastic prices, features and support!

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Cool! Another CodeProject fan!

The C2DPushGraph (C++ and C#) ones look good. I also found another really nice C# one: http://www.codeproject.com/cs/miscctrl/SimplePerfChart.asp

Tim. Is your current project in Win32 or MFC? Are you just working on a small bit of a larger interface? Or is your application only going to show the line chart and that's all?

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
quote:
Originally posted by ssquared:
Cool! Another CodeProject fan!

The C2DPushGraph (C++ and C#) ones look good. I also found another really nice C# one: http://www.codeproject.com/cs/miscctrl/SimplePerfChart.asp

Tim. Is your current project in Win32 or MFC? Are you just working on a small bit of a larger interface? Or is your application only going to show the line chart and that's all?


Wow, this one looks promising! It mentions real-time!

Thanks for all your help everyone!! Kicking myself for not asking you guys last week!!

Steve - I'm too ignorant to answer your question! It is Win32 (XP but my Visual Studio is like WAY OLD, before .NET). But if MFC (the foundation classes) help me get further along, I don't mind using them.

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
I have Visual Studio 6 (c) 1998. And this perfchart looks like it uses C#
http://www.codeproject.com/cs/miscctrl/SimplePerfChart.asp

I've been told it may be difficult to get this to work in the version of Visual Studio I have ... can you experts confirm?

So, I may have to jump into Visual Basic or .net (ack).

Let me check out some of the others to see if they are C++ native.

Thanks,
Tim

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
You probably won't get any C# ones working in VC++6.0, unless you're willing to do a LOT of porting and re-writing. Even finding C++ ones, you may still have issues (6.0 predates .NET features, MFC/Win32 library differences, etc.)

Another option is to use the Visual C++ 2005 Express and/or Visual C# 2005 Express (and/or Visual Basic 2005 Express), which are all available for free: http://msdn.microsoft.com/vstudio/express/

A third option if you want to upgrade but don't want the Express editions and the non-free editions are too much $$$ is Ebay.

------------------
Brian

"OOP programmers have a lot of class"

Check out this webhost! Fantastic prices, features and support!

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
I wasn't sure if you wanted C# or not. Your title says 'no'.

Visual Studio 6 does not work with C# nor allow you to do anything with .NET. You should really get the 'almost' free version of Visual Studio Standard while there is still time (end of June).

Or you can download the completely free versions of C++ Express and/or C# Express.

The other one which looked nice (C2DPushGraph) was mentioned by BrianT. It was written for both C++ and C#.

There are two ways to approach the C# version. You can write the application in C# and call your 'C' routines. Or you can write the application in C++ and call the C# code. Knowing what you have already will help. Do you already have a C++ application? Are the 'c' routines in a DLL or part of your application?

Using the C# version will require a big learning curve on your part, so it may not be the route you want to go. I can give you examples of how to talk between C# and C, but I think going with C++ may be your best choice right now.

If this is something for Gracworks Interactive, I may be able to help.

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Thanks guys.

Nope this is for my day job. So, I should be able to get the full version of Visual Studio as we probably have site license.

The concern is the code I have now is straight C as part of the application - if perfchart can be used "from" that easily in the new Visual Studio, then I'll run in that direction. It should be "easy" The PerfChart comes as a .DLL - so Steve's suggestion of calling the C# should work (although not with the old version of Vis Studio that I have). You said C++ over C - the code should compile fine

VB6 was also suggested since using controls and DLLs is "easier" - do you experts believe that is a useful path? I believe I have VB6 (which is pre-.net installed already).

Oh, the joys of software! Can't we all go back to assembly!! Or Forth?

Brian - this version 6 mentions MFC/Win32 but probably the early incarnations. So I should shoot it and put it out of its misery? It worked fine but again, just displaying the results of the code in a command window, how complex!

I should probably get that almost free for GraceWorks though - thanks for the expiration reminder.

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
Pure 'C' code should still compile and run fine in any C++ compiler, but you *may* end up having to tweak a few settings/flags/warnings depending how old the C code is. If you want to call any C# code from C++ though, your C++ project will have to be "managed" i.e. .NET (C# *is* .NET (="managed"), while C++ (in Visual Studio) *can* be, in case you're not clear on that - or did that just add to the confusion?).

I don't know VB at all, but unless it's .NET also, you can't call .NET dlls. Calling .dlls is easy enough in C++ though (in my opinion)

I'd keep that VC6.0 around. I used it for years, it's still a great compiler although a bit dated now. You can install newer VS compilers on the same machine and they will act completely independently from one another, so there's no harm or risk in keeping VC6.0 installed.

------------------
Brian

"OOP programmers have a lot of class"

Check out this webhost! Fantastic prices, features and support!

Briant

Member

Posts: 742
From: Stony Plain, Alberta, Canada
Registered: 01-20-2001
Correction: apparently it IS possible to call .NET .dlls from non-.NET code. I've never done it myself, but there are a few different solutions if you Google.

------------------
Brian

"OOP programmers have a lot of class"

Check out this webhost! Fantastic prices, features and support!

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Don't think version 6 is some inferior verison of MFC. They didn't update it all that much over the years. I get plenty of old code examples written in Visual Studio 6 and have almost no issues opening and compiling the projects. There are often some minor tweaks, but nothing major.

Calling C# from C++ is fairly straightforward. It's an area I have been studying, learning, researching, and using for about a year. I've even thought about being a C++ to C# consultant to help companies get their old legacy apps moving forward with new technology. Although once they realize how easy it is, maybe they wouldn't want a consultant. Anyway, I believe it's actually a major factor in how I got my current job.

[This message has been edited by ssquared (edited June 21, 2007).]

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
quote:
Originally posted by ssquared:
Calling C# from C++ is fairly straightforward. It's an area I have been studying, learning, researching, and using for about a year. I've even thought about being a C++ to C# consultant to help companies get their old legacy apps moving forward with new technology. Although once they realize how easy it is, maybe they wouldn't want a consultant. Anyway, I believe it's actually a major factor in how I got my current job.

Then write an Ebook and use your profits to fund some crazies trying to make Christian Games! ;-0 Sorry, couldn't resist.

I do have access to V. Studio 2005 at work - making the CDs now. I may beg for an early copy of the Ebook as I really like the PerfChart implementation (one in C#).

The other one - C2DPushGraph - looks good too, functional and should work under the old visual studio (I'll D/L and try).

Thanks so much for the help! Great appreciated.

Tim

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Hmm, looks like I can't easily add the .dll for C2DPushGraph in the old visual studio.

Plus, the code doesn't provide its own interval timer.

Going to install VS 2005 now.

-Tim

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
quote:
Originally posted by GraceWorks:
Then write an Ebook

Well, I've thought about putting an article up on CodeProject, but it's just another one of those items on my list that never gets done.

quote:
I may beg for an early copy of the Ebook as I really like the PerfChart implementation (one in C#).

Well, I do have a sample project I have been working on which contains a few examples of C++ using C#. But nothing much. My sample project is really focused on the other side. C# calling C. My C++ to C# work has been mostly on the job so all of my code was for work. I have been doing the C# to C thing as my own research project, so I have a growing suite of tests and examples for that.

I will expand the C++ --> C# examples if you would like to take a look.

This exact topic is actually one of my reasons I enjoy C# so much. Microsoft did such a terrific job of cross-language development (which is one of the things .NET is all about). Java has the Java Native Interface (JNI) which is a pain to use and really slows down development time.

[qoute]The other one - C2DPushGraph - looks good too, functional and should work under the old visual studio (I'll D/L and try).[/quote]

I agree. I think you should at least try that one. See if you can integrate it into your project. That way, if the C# one doesn't work out, you have something else you know works.

BTW, I do believe CodeProject's rules allow you to use the code in any way you want, but I still recommend e-mailing the author and asking if it's OK. I just used someone's code this week and need to do that myself.

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Just finished installing VStudio 2005.

And was able to recompile and run my original code - it works! Yeah. Although, I did get 24 warnings most about my code deprecating (now software should REALLY not be allowed to do that). They said what to set to get rid of them, so may do that or just live with the warnings.

Added the C2DPushGraph - but now have to re-learn how to do forms! I'll keep ya'll posted.

Tim

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
That's great to hear it compiled and worked! That is a positive start.

Don't worry about the warnings. Although with 24 of them, it's easy enough to just clean those up. Personally, I like having 0 warnings. Basically, VS2005 deprecated a lot of the old 'C' functions and gave them new safe versions. This is actually pretty cool and quite helpful. They now do bounds checking and will throw exceptions if there is a problem.

For example, 'strcpy' now has a safe version REQUIRING you to pass in the number of chars to copy. Kind of like strncpy, but that has no bounds checking and safety checks. If there is a problem with strncpy, you just crash.

Let us know how the integration goes.

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
Okay - I'm going to need your ebook - both C2DPushGraph and PerfChart are C#, my code is C. Plus I haven't used this environment for years (VB5?), so mega rusty on how to dink with forms. I was able to add the C2D but couldn't do much with it and the demo is in C# (same as PerfChart).

I'll get busy learning. Is this something that is easy for some of you experts?

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
There is a C++ version of C2DPushGraph which you may want to look at. As far as I can tell, PerfChart seems to be the best one. The control ALREADY has the timer functionality built in. All you need to do is call Add at some set interval and the control takes care of the rest. Pretty nifty. C2DPushGraph is nice, but requires a bit more overhead on the part of the developer. Even so, I still think your easiest bet is to use the C++ version of C2DPushGraph.

It will be very helpful to know if what you are working on is part of a larger application or if it is a stand-alone application. The answers to the following questions are an important factor in what you can and can't do moving forward.

For example, is there already a user interface with buttons, boxes, and all sorts of stuff? Is your piece just one more component within this particular window full of already placed UI components? Or is your application just a stand alone app and has nothing to do with anything else? Are you starting the application from scratch? Are the 'c' calls contained within a DLL? Are you expecting the application's UI to only be this special control? Or is this a larger application and the graphing functionality will be accessed via a menu item?

These questions are helpful because it will help me (or anyone else) tailor answers and help in the direction most appropriate for your needs.

Edit: I'll see about getting a small sample up tonight, but I am watching my two girls tonight and will be out of town tomorrow. They tend to stay up until 10 PM now that there is no school. I took a quick break to edit and write this.

[This message has been edited by ssquared (edited June 22, 2007).]

graceworks
Member

Posts: 455
From: Corvallis, Oregon, USA
Registered: 03-03-2001
quote:
Originally posted by ssquared:
There is a C++ version of C2DPushGraph which you may want to look at. As far as I can tell, PerfChart seems to be the best one. The control ALREADY has the timer functionality built in. All you need to do is call Add at some set interval and the control takes care of the rest. Pretty nifty. C2DPushGraph is nice, but requires a bit more overhead on the part of the developer. Even so, I still think your easiest bet is to use the C++ version of C2DPushGraph.

I agree - PerfChart would be perfect other than have to get the C to call C# DLL to work. I'll dig into the C++ version of C2D - forgot he had both.

quote:
It will be very helpful to know if what you are working on is part of a larger application or if it is a stand-alone application. The answers to the following questions are an important factor in what you can and can't do moving forward.

Probably best to classify it as a stand-alone application - main thing is displaying the various signals on the line chart (up to 6 potentially - if we can only show two at once, that is probably okay).

quote:
For example, is there already a user interface with buttons, boxes, and all sorts of stuff? Is your piece just one more component within this particular window full of already placed UI components? Or is your application just a stand alone app and has nothing to do with anything else? Are you starting the application from scratch? Are the 'c' calls contained within a DLL? Are you expecting the application's UI to only be this special control? Or is this a larger application and the graphing functionality will be accessed via a menu item?

Currently, it runs in a command prompt window - displaying text. The U/I is actual keyboard - hit "S" to stop A/D, A through H to select what channel's data to display, etc. So, no forms exist yet! So, the application "works" - it gathers data and displays it on screen (or logs it to the optional log file as well), so definitely not from scratch. When you launch, if the line chart window popped open and stayed open the whole time, that would be acceptable.


quote:
These questions are helpful because it will help me (or anyone else) tailor answers and help in the direction most appropriate for your needs.

Thanks! It is obvious that I haven't used these tools in a long time (well, the last time was actually Visual Basic, version 5 if I recall).

quote:
Edit: I'll see about getting a small sample up tonight, but I am watching my two girls tonight and will be out of town tomorrow. They tend to stay up until 10 PM now that there is no school. I took a quick break to edit and write this.

Ack, I hate to put you out bro. If it works better for you, wait until Monday. I'll be trying to learn more this weekend.

Thank you for your effort! Greatly appreciated!
[/QUOTE]

------------------
Called by God. The passioned plea of a father. The journey awaits at Jarod's Journey.
Participate in the Parables, The Interactive Parables

GWI 1up | GWI MySpace

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
Great! That is helpful information.

I e-mailed you a ZIP file with an example of a Win32 application displaying PerfChart. A description TXT file is included. Not sure how far it will get you, but you can use it as an example of what needs to be done.

The example displays the dialog through a menu item which may not be the best for what you want. You may need to create what is called a Dialog Application. This is, as the name implies, an application where the main UI is a dialog. I think this option is only available for creating an MFC-based application, though. I don't want to throw an extra layer of technology for you to learn.

quote:
main thing is displaying the various signals on the line chart (up to 6 potentially)

I think PerfChart only allows one at a time. You will need to extend it to maintain multiple lines.

quote:
It is obvious that I haven't used these tools in a long time

No problem. Glad to see you got updated. Hopefully you'll dig around with the new tools and enjoy what you find.

quote:
Ack, I hate to put you out bro.

I get ecstatic about this type of project. I feed off GUI development. This would be a fun one. You sure it's not for Graceworks?

Side-note: I just e-mailed someone about the potential need to convert his old Visual Studio 6 project to VS 2005 and perhaps .NET. Kind of funny to see this opportunity right after I mentioned it yesterday. I asked for more information.