For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > March 2004 > Real Time MSChart Plotting, Suggestions Needed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Real Time MSChart Plotting, Suggestions Needed
GrindKore

2004-03-30, 12:30 pm

Hello VB gurus, I have been battling MSChart control for 2 days now. I do
realize it's not the best and in fact could be the worst chart control, but
it's free. The application I'm working on is fairly simple, basically I need
to plot data from load cell on a PC. I wrote ActiveX interface for all
serial comm. handling so only thing I need to figure out is how to plot data
using MSChart. My AX object fires event on parent form every 250ms and
returns three parameters, below is actual code snip from my app.

Private Sub objDataDrv_OnTestData(ByVal LoadVal As Long, ByVal PeakVal As
Long, ByVal Timestamp As Single)
Debug.Print LoadVal, PeakVal, Timestamp
End Sub



The chart should be a line type where X-axis is time in seconds and Y-axis
is numeric force value returned
by the load cell. Sounds simple enough, but I cannot find any examples of
plotting line graphs in real time.

Any input is appreciated, thank you in advance....


Ivar

2004-03-30, 2:30 pm

Hello

I had a play. On a form put the mschart and a timer then add this code
'##Start of code
Option Explicit

Private Sub objDataDrv_OnTestData(ByVal LoadVal As Long, _
ByVal PeakVal As Long, ByVal Timestamp As Single)
Dim I As Integer, TempVal As Integer
With MSChart1
For I = 1 To 19
.Row = I
.RowLabel = Timestamp + (1 + I)
.Row = I + 1
TempVal = .Data
.Row = I
.Data = TempVal
Next
.Row = 20
.Data = LoadVal
.RowLabel = Timestamp + 21
End With
End Sub

Private Sub Form_Load()
Dim I As Integer
With MSChart1
..SeriesType = VtChSeriesType2dLine
..ColumnCount = 1
..RowCount = 20
For I = 1 To 20
..Row = I
..RowLabel = I
Next
End With
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Static StartTime As Integer
Dim RndNumber As Integer
Randomize
RndNumber = (100 * Rnd) + 1
StartTime = StartTime + 1
objDataDrv_OnTestData RndNumber, 0, StartTime
End Sub
'##End of Code
Y axis being a random value, X axis being seconds running
It might be something like you're looking for. Didn't use "PeakVal", Don't
know what it's for.
The Chart should update once every second appearing to move from right to
left


Bonj

2004-03-30, 2:30 pm

Having been in the charts industry for 4 years, I've not come across yet a
'chart component' that works adequately. The *only* things that can generate
charts properly are: a LOT of manual GDI code, Excel, and possibly Crystal
Reports and BusinessObjects. I use Excel personally.

"GrindKore" <grindkore{123SPAM456}@yahoo.com> wrote in message
news:a4f7c5e7faa85e6fb153e71c313d1b30@un
limited.ultrafeed.com...
> Hello VB gurus, I have been battling MSChart control for 2 days now. I do
> realize it's not the best and in fact could be the worst chart control,

but
> it's free. The application I'm working on is fairly simple, basically I

need
> to plot data from load cell on a PC. I wrote ActiveX interface for all
> serial comm. handling so only thing I need to figure out is how to plot

data
> using MSChart. My AX object fires event on parent form every 250ms and
> returns three parameters, below is actual code snip from my app.
>
> Private Sub objDataDrv_OnTestData(ByVal LoadVal As Long, ByVal PeakVal As
> Long, ByVal Timestamp As Single)
> Debug.Print LoadVal, PeakVal, Timestamp
> End Sub
>
>
>
> The chart should be a line type where X-axis is time in seconds and Y-axis
> is numeric force value returned
> by the load cell. Sounds simple enough, but I cannot find any examples of
> plotting line graphs in real time.
>
> Any input is appreciated, thank you in advance....
>
>



GrindKore

2004-03-30, 3:30 pm

Thank you very much, this is very helpful. Now I'm going to write a little
wrapper class to hide all the MSChart "ugliness".

"Ivar" <ivarekstromer@ntlworld.com> wrote in message
news:AUiac.3$A46.2@newsfe2-gui.server.ntli.net...
> Hello
>
> I had a play. On a form put the mschart and a timer then add this code
> '##Start of code
> Option Explicit
>
> Private Sub objDataDrv_OnTestData(ByVal LoadVal As Long, _
> ByVal PeakVal As Long, ByVal Timestamp As Single)
> Dim I As Integer, TempVal As Integer
> With MSChart1
> For I = 1 To 19
> .Row = I
> .RowLabel = Timestamp + (1 + I)
> .Row = I + 1
> TempVal = .Data
> .Row = I
> .Data = TempVal
> Next
> .Row = 20
> .Data = LoadVal
> .RowLabel = Timestamp + 21
> End With
> End Sub
>
> Private Sub Form_Load()
> Dim I As Integer
> With MSChart1
> .SeriesType = VtChSeriesType2dLine
> .ColumnCount = 1
> .RowCount = 20
> For I = 1 To 20
> .Row = I
> .RowLabel = I
> Next
> End With
> Timer1.Interval = 1000
> Timer1.Enabled = True
> End Sub
>
> Private Sub Timer1_Timer()
> Static StartTime As Integer
> Dim RndNumber As Integer
> Randomize
> RndNumber = (100 * Rnd) + 1
> StartTime = StartTime + 1
> objDataDrv_OnTestData RndNumber, 0, StartTime
> End Sub
> '##End of Code
> Y axis being a random value, X axis being seconds running
> It might be something like you're looking for. Didn't use "PeakVal", Don't
> know what it's for.
> The Chart should update once every second appearing to move from right to
> left
>
>



Dick Grier

2004-03-31, 10:30 am

Hi,

I use 3rd party controls (or my own in a PictureBox), such as IOComp and
National Instruments. You can see examples and other information on the PC
Data Acquisition link on my homepage.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com