ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to set up multiple time range for real time track chart
Posted by cici on Apr-01-2015 21:29
Hi,

I need a function for adding multiple time select range in the real time running chart for
my VB.NET project.

The default chart XAxis time range is 1 min, I want have a ComboBox can select different
time ranges ( for example: 15mins, 30mins, 1hr, 2hrs...).
Please help me with this issue!

Thank you!

CiCi

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Apr-02-2015 04:17
Hi cici,

In brief, instead of hard coding the time range, you just need to set the time range
according to the combo box. The exact details depend on the type of application you are
writing. Are you using VB.NET to write a Windows Forms or ASP.NET application?

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by cici on Apr-02-2015 21:17
Hi Peter,

Thanks for your reply!
I am using VB.NET design Windows Form.
I already tried to add ComboBox and changed sampleSize, here is my code:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
        Dim sampleSize As Integer
        Dim dataSeriesA(sampleSize - 1) As Double
        Dim dataSeriesB(sampleSize - 1) As Double
        Dim dataSeriesC(sampleSize - 1) As Double
        Dim timeStamps(sampleSize - 1) As Date
        Select Case ComboBox1.SelectedItem.ToString
            Case "15 min"
                sampleSize = 3600
            Case "30 min"
                sampleSize = 7200
            Case "1 HR"
                sampleSize = 14400
            Case "2 HR"
                sampleSize = 28800
            Case "4 HR"
                sampleSize = 57600
            Case "8 HR"
                sampleSize = 115200
        End Select
    End Sub

It seems there is still some codes I need to modified since the time XAxis still not
changed.

Thanks

CiCi

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Apr-03-2015 02:49
Attachments:
Hi cici,

There are some issues in your code. The dataSeriesA, dataSeriesB, dataSeriesC, etc, are
local variables, which means they will be destroyed after leaving the event handler. So they
have no effect. Then the sampleSize is used to specify the array diemension, which means
the code that sets the sampleSize has no effect.

The arrays are only used to store the data, so that your can plot the data. The code to
plot the chart is in drawChart, and the x-axis scale is configured using Axis.setDateScale. If
you would like to change the x-axis scale, you would need to change the code in
drawChart. For the arrays, it just needs to be big enough to store your data. You can
simply hard code a big enough value.

I have attached an example for your reference. It is modified from the "Realtime Chart with
Track Line" sample code.

Hope this can help.

Regards
Peter Kwan
realtimetrack.zip
realtimetrack.zip

8.53 Kb

  Re: How to set up multiple time range for real time track chart
Posted by cici on Apr-16-2015 00:04
Thank you,Peter! It works!

Right now, I have another request.

If the X-axis range is 2 hours, is there any way I can draw the chart have the 2 hours
history graph and the real time running graph display in the same chart? I am acquiring
data from SQL server.

CiCi

  Re: How to set up multiple time range for real time track chart
Posted by cici on Apr-16-2015 02:39
Attachments:
Hi Peter,

I have attached word file includes the explain chart.
I need the function is when user run program, the chart will display 2 hours history chart
and continue running the updated real time data.

Thanks

CiCi
explain chart.docx
explain chart.docx

22.58 Kb

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Apr-16-2015 10:43
Hi cici,

In the sample code, the data arrays are initially empty, and is then filled with random
values. In your real code, you can initially fill the data arrays with the data from your
database, and then fill with your actual realtime values (instead of random numbers). This
will achieve what you need.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by cici on Apr-17-2015 05:56
Hi Peter,

Yes, I do get my data from SQL tatble for the real time running data.
But I still need the function for display 2 hours history data when I start my program
(means the 2 hours history chart trend is already showed in the chart, and at the same
time pen is drawing real time running data)

Thanks

cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Apr-18-2015 02:10
Hi cici,

First, write some code to read your historical data and store them in the data arrays. Then,
for the real time data, please append them to the data arrays. Then use the data arrays to
plot the chart.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by cici on Apr-18-2015 04:46
Thanks for your reply!
I will try it.

cici

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-10-2019 02:24
Hi Peter,

I know this question has been while. But I still didn't achieve the function that I want. (Show the 2 hours historical and the real time data on the same chart)
If that is possible can you provide me some example? I am using VB.NET and MS SQL.
I am struggled in this problem for a long time.

Thanks in advanced!

Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Oct-11-2019 02:55
Hi Cici,

I assume you know how to read data from a database into array variables. (This part does not involve ChartDirector and is just normal VB code.)

First, read the historical data into array variables:

'Read historical data as arrays
timeStamps = .... historical data ....
dataSeriesA = .... historical data ....

'Extend the arrays by 1000 elements so you can add realtime data to the array
currentIndex = timeStamps.Length
Array.Resize(timeStamps, timeStamps.Length + 1000)
Array.Resize(dataSeriesA, dataSeriesA.Length + 1000)

For i As Integer = currentIndex to timeStamps.Length
     timeStamps(i) = DateTime.MinValue
Next


Now in your charting code, configure the x-axis scale to include the time range of the historical data plus the 1000 elements, like:

'samplingPeriod is the time between two realtime samples
c.xAxis().setDateScale(timeStamps(0), timeStamps(currentIndex - 1).Add((timeStmaps.Length - currentIndex) * samplingPeriod))


Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-11-2019 04:44
Hi Peter,

Thanks for your quick reply!
You mentioned TimeStamps and dataSerialA array = ...historial data...,
are they defined as an array that store my actual historical data and equal to each other?

Because in your example code, they defines as the following:

Private Const sampleSize As Integer = 115200
Private dataSeriesA(sampleSize - 1) As Double
Private timeStamps(sampleSize - 1) As Date

I am a little bit confuse.

Cici

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-11-2019 05:15
And in the Drawchart part, I am using combobox to choose different time range(12/24/72 Hour), here is my code:


        ' Now we add the data to the chart
        If currentIndex > 0 Then
            ' Set up the x-axis scale.
            Dim lastTime As DateTime = timeStamps(currentIndex - 1)
            Dim duration As Integer = getDuration()

            c.xAxis().setDateScale(lastTime.AddSeconds(-duration), lastTime)

            Dim pointCount As Integer = duration * 1000 / dataRateTimer.Interval

            c.setTrimData(currentIndex - pointCount, pointCount)

            ' Set the x-axis label format
            c.xAxis().setLabelFormat("{value|hh:nn:ss}")

            ' Create a line layer to plot the lines
            Dim layer As LineLayer = c.addLineLayer2()
            layer.setFastLineMode()

            ' The x-coordinates are the timeStamps.
            layer.setXData(timeStamps)

            layer.addDataSet(dataSeriesA, &HFF0000, "PVC <*bgColor=FFCCCC*>").setUseYAxis2()
            layer.addDataSet(dataSeriesB, &HCC00, "RCL <*bgColor=CCFFCC*>")
            layer.addDataSet(dataSeriesC, &HFF, "C <*bgColor=CCCCFF*>").setUseYAxis(leftAxis)
            layer.addDataSet(dataSeriesD, &HFFFF, "D1 <*bgColor=B6FFFD*>")
            layer.addDataSet(dataSeriesE, &HFF00FF, "D2 <*bgColor=F9B6FF*>")
        End If

        ' Include track line with legend. If the mouse is on the plot area, show the track
        ' line with legend at the mouse position; otherwise, show them for the latest data
        ' values (that is, at the rightmost position).
        trackLineLegend(c, IIf(viewer.IsMouseOnPlotArea, viewer.PlotAreaMouseX, _
            c.getPlotArea().getRightX()))

        ' Assign the chart to the WinChartViewer
        WinChartViewer3.Chart = c

The setDateScale has been changed. I changed it according to the example file that you attached.

Here is the code:
c.xAxis().setDateScale(lastTime.AddSeconds(-duration), lastTime)

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Oct-11-2019 12:42
Hi Cici,

There are many ways to create arrays. In the sample code, the size is hard coded to a fix size and all the timeStamps are initialized to DateTime.MinValue.

The code in my last message is another method to create the arrays:

(a) Write some code to read your historical data into arrays. Let's call the timestamp array timeStamps and the data array dataSeriesA. (Assume one data series.) This part is not related to ChartDirector. Of course in this case you do not need to hard coded the array size. It only requires the variables to exist, like:

Private dataSeriesA As Double()
Private timeStamps As Date()

(b) Extend the arrays to whatever size is necessary so that it can hold additional realtime data. Initialize the extended part of the timeStamps array to DateTime.MinValue as they contain no data yet. Set the currentIndex to the size of the historical data, so the data acquisition code knows where to append new data.

If you prefer to hard coded the array size, you can:

- Write some code to read your historical data into the arrays. The arrays are assumed to be larger than the historical data size, so that there are some elements left for the realtime data. Initialize the rest of the timeStamps array with DateTime.MinValue. Set the currentIndex to the size of the historical data, so the data acquisition code knows where to append new data.

Hope this can help.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-12-2019 00:55
Hi Peter,

Based on my understanding, I need to do the following steps (using the Hard code the array size):

(a) Read historical data into the arrays.

    Private Const sampleSize As Integer = 115200
    Private dataSeriesA(sampleSize - 1) As Double
    Private timeStamps(sampleSize - 1) As Date

(b) Initial the extended part of the timeStamps array with DateTime.MinValue.

     ' Initialize data buffer. In this demo, we just set the initial state to no data.
        Dim i As Integer
        For i = 0 To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

(c) Set the currentIndex to the size of the historical data.

As the sample code, the currentIndex is defined as the following:

  ' The index of the array position to which new data values are added.
    Private currentIndex As Integer = 0

    Private Sub dataRateTimer_Tick(sender As Object, e As EventArgs) Handles dataRateTimer.Tick

        Do While nextDataTime < DateTime.Now

            ' After obtaining the new values, we need to update the data arrays.
            If currentIndex >= timeStamps.Length Then
                Dim trimAmount As Integer = (timeStamps.Length + 99) / 100
                Dim i As Integer
                For i = trimAmount To UBound(timeStamps)
                    timeStamps(i - trimAmount) = timeStamps(i)
                    dataSeriesA(i - trimAmount) = dataSeriesA(i)
                Next
                currentIndex -= trimAmount
            End If

            ' Store the new values in the current index position, and increment the index.
            dataSeriesA(currentIndex) = dataA
            timeStamps(currentIndex) = nextDataTime
            currentIndex += 1

            ' Update nextDataTime. This is needed by our data generator. In real applications,
            ' you may not need this variable or the associated do/while loop.
            nextDataTime = nextDataTime.AddMilliseconds(dataRateTimer.Interval)
        Loop
    End Sub

Do I need to modify the code on dataRateTimer_Tick event as above?

(d) I have a question:

Do I need to create another array to store real time data (like dataSeriesA(sampleSize-1)?
If not, how can the historical data and the real time date connect to each other?

Thanks for your help!!
Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Oct-12-2019 16:30
Hi Cici,

The code in the (b) part is incorrect. It overwrites your historical data in the (a) part. The code should be:

currentIndex = .... size of your historical data ....

' Only initialize the part of the array that has no historical data
Dim i As Integer
For i = currentIndex To UBound(timeStamps)
      timeStamps(i) = DateTime.MinValue
Next

You do not need to create any dataSeriesA if you use the hard coded dataSeriesA. Otherwise, the data used in the hard coded dataSeriesA will become inaccessible.

If you continue to use the sample code (which generates pseudo random data), you do not need to modify the dataRateTimer_Tick code.

The historical data occupies the array from index 0 to currentIndex - 1. In the dataRateTimer_Tick, new data are appended at currentIndex. So the new data will follow the historical data in the chart.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-30-2019 05:23
Hi Peter,

I already retrieved data from database and store to array.

You mentioned the part (b):

currentIndex = .... size of your historical data ....

' Only initialize the part of the array that has no historical data
Dim i As Integer
For i = currentIndex To UBound(timeStamps)
      timeStamps(i) = DateTime.MinValue
Next

My original code already has the following code:

' Initialize data buffer. In this demo, we just set the initial state to no data.
        Dim i As Integer
        For i = 0 To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next


For my understanding, I need to keep my original code and recreate another timestamps array,right?
Like:
Dim i As Integer
For i = currentIndex To UBound(timeStamps)
      timeStampsSecond(i) = DateTime.MinValue
Next

Thanks!
Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Oct-30-2019 16:43
Hi Cici,

You only need to real data into arrays that are used by your charting code. In the original charting code, it uses the timeStamps array. So it is not useful to read data into the timeStampsSecond array because the charting code does not use the array at all.

According to your previous message, you code is like:

(a) Read historical data into the arrays.

.......

(b) Initial the extended part of the timeStamps array with DateTime.MinValue.

     ' Initialize data buffer. In this demo, we just set the initial state to no data.
     Dim i As Integer
     For i = 0 To UBound(timeStamps)
         timeStamps(i) = DateTime.MinValue
     Next

The above is incorrect, because (b) will overwrite (a).

You can reverse the order if you like, that is, initialize the array first, then load data into the arrays. Although this is less efficient that my suggested code, it would still work.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Oct-31-2019 04:44
Hi Peter,

I am totally lost, sorry!

I follow the steps that you suggested before:

(a) Write some code to read your historical data into arrays (I already finished)

Private dataSeriesA As Double()
Private timeStamps As Date()

(b) Extend the arrays to whatever size is necessary so that it can hold additional realtime data.

currentIndex = .... size of your historical data ....

' Only initialize the part of the array that has no historical data
Dim i As Integer
For i = currentIndex To UBound(timeStamps)
      timeStamps(i) = DateTime.MinValue
Next

Does this work? Do I need to keep my original code for the timeStamps?

If this works, another question, if I want to display the last 12 hours data, what's the value of currentIndex should be assigned?

Thanks,
Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-01-2019 00:14
Hi Cici,

If your original code is to initialize the whole array, then you do not need to keep your original code. The code in your previous message has already initialize the unused part of the arrays.

The currentIndex is the size of your historical data. If you need 12 hours of historical data, and those 12 hours contain 1741 timeStamps, then the first 1741 elements of the timeStamps array should already been filled with your 12 hours of data. That means currentIndex should be 1741, which is the position new realtime data are to be added.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-12-2019 05:31
Attachments:
Hi Peter,

I followed your suggestion, but got error. Please see attached picture.

Thanks,
Cici
37.jpg

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-13-2019 02:47
Hi Cici,

The error message means one of the DateTime in that line is not valid in .NET. Since lastTime must be valid, it is likely to be the lastTime.addSeconds(-duration) that is invalid.

Note that in .NET, as in any programming language, the DateTime has a range limit. For example, .NET DateTime cannot represent a date/time that is 5000 years ago. In .NET, the earliest DateTime possible is Jan 1, 0001 00:00:00.

Please examine in your debugger to see what is the value of lastTime and duration. If you pushback lastTime by duration, does not go before Jan 1, 0001 00:00:00?

If your code is not interested in the year part of the DateTime, please at least use a reasonable date (like Jan 1, 2010) when your code create the DateTime objects.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-13-2019 05:35
Hi Peter,

Yes, The default value of Date is 0:00:00 (midnight) on January 1, 0001.

I got this error since set currentIndex to 1741:

       currentIndex = 1741
        For i = currentIndex To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

And the error happens in the following code:
            If currentIndex > 0 Then
            ' Set up the x-axis scale.
            Dim lastTime As DateTime = timeStamps(currentIndex - 1)
            Dim duration As Integer = getDuration()
            c.xAxis().setDateScale(lastTime.AddSeconds(-duration), lastTime)

It seems like related to the currentIndex setting value.

I will try to fix it.

Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-13-2019 17:34
Hi Cici,

If currentIndex = 1741, that means you have 1741 historical data points. So timeStamps(0) to timeStamps(1740) should contain your historical data, and timeStamps(1740) should come from your historical data, not the default value. Would you mind to check if you have 1741 points of historical data, and if their timestamps are correct?

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-15-2019 01:48
Hi Peter,

I debug my code.

Original code:
         ' Initialize data buffer. In this demo, we just set the initial state to no data.
        Dim i As Integer
        For i = 0 To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

Result:
currentIndex: 110, lastTime: 11/14/2019 11:09:01


Current code:
         ' Initialize data buffer. In this demo, we just set the initial state to no data.
        currentIndex = 1741
        For i = currentIndex To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

Result:
currentIndex: 1741, lastTime: 00:00:00

The problem is caused by lastTime

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-15-2019 15:01
Hi Cici,

Do you mean you already know what is the problem and has already fixed the problem?

If you have not yet fixed the problem, please let me what is your code, and why currentIndex is 1741. The code should be:

.... Write some code to read your historical data into arrays ....
currentIndex = .... size of your historical data ....

For i = currentIndex To UBound(timeStamps)
      timeStamps(i) = DateTime.MinValue
Next

The lastTime comes from your historical data. If the first part "Write some code to read your historical data into arrays" is incorrect, or your currentIndex is incorrect (it should be the size of your historical data), then it will cause the problem you see. You can add a Debug.Assert statement to check if your data is correct.

currentIndex = .... size of your historical data ....

' Check if your historical data are correct
System.Diagnostics.Debug.Assert(timeStamps(currentIndex - 1) <> DateTime.MinValue, "The historical data have an invalid timeStamp.")

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-15-2019 22:54
Attachments:
Hi Peter,

I haven't fix the problem yet.

I set the currentIndex to 1741 because you suggested if I want to get 12 hours historical date, I need to set the currentIndex value to 1741.
Since my test database only has 105 rows, so I set my currentIndex to 100. But still doesn't work.

I already tried your debug code:
' Check if your historical data are correct
System.Diagnostics.Debug.Assert(timeStamps(currentIndex - 1) <> DateTime.MinValue, "The historical data have an invalid timeStamp.")

It pops out error message (please see the zipped attach file)

My current code is :

         ' Initialize data buffer. In this demo, we just set the initial state to no data.
        currentIndex = 100
        For i = currentIndex To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

I tried to attache my vb.net project file to you, but the file size is limited to 250K (Even I zip it still over the size)

Thanks,
Cici
34.jpg
33.rar
33.rar

250.01 Kb

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-16-2019 18:19
Hi Cici,

The error means the timeStamps in your data are not correct.

In the image in your post, I see a SQL query that returns 8 columns - Chart_dataA up to Chart_dataI. It does not seem to have a column for the timeStamps. Would you mind to clarify how do you fill the timeStamps array with your historical data? Is it possible to provide the code that you use to read from the database data into the timeStamps and dataSeriesA arrays?

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-19-2019 01:29
Hi Peter,

Yes, I have 9 arrays Chart_dataA to Chart_dataI which presents 9 pens for chart.

Here is the code how I fill the timeStamps array with the historical data:

a) Write some code to read historical data into arrays
    'realtime chart
    ' The data arrays that store the visible data. The data arrays are updated in realtime. In
    ' this demo, we plot the last samples for 12/24/72 hours
    Private Const sampleSize As Integer = 115200

    '5 scale weight A,B,C,D1,D2
    Private dataSeriesA(sampleSize - 1) As Double
    Private dataSeriesB(sampleSize - 1) As Double
    Private dataSeriesC(sampleSize - 1) As Double
    Private dataSeriesD(sampleSize - 1) As Double
    Private dataSeriesE(sampleSize - 1) As Double

    '2 temperature, 2 current for 2 mixers
    Private dataSeriesF(sampleSize - 1) As Double
    Private dataSeriesG(sampleSize - 1) As Double
    Private dataSeriesH(sampleSize - 1) As Double
    Private dataSeriesI(sampleSize - 1) As Double

    Private timeStamps(sampleSize - 1) As Date

    ' The index of the array position to which new data values are added.
    Private currentIndex As Integer = 0

(b) Extend the arrays to whatever size is necessary so that it can hold additional realtime data

currentIndex = 100

' Only initialize the part of the array that has no historical data
Dim i As Integer
For i = currentIndex To UBound(timeStamps)
      timeStamps(i) = DateTime.MinValue
Next

(c) code for read database data into dataSeriesA

Sub ReadFromDBtoArray()
      Dim connectionString As String = "Data Source=MININT-BJDM4MISQLEXPRESS;AttachDbFilename=C:Program FilesMicrosoft SQL ServerMSSQL12.SQLEXPRESSMSSQLDATAMixerHMI.mdf;Database=MixerHMI;Trusted_Connection=Yes;"
        Dim Sql As String = "SELECT * FROM ChartData"
        Dim connection As New SqlConnection(connectionString)
        Dim dataadapter As New SqlDataAdapter(Sql, connection)
        Dim ds As New System.Data.DataSet()
        Dim cmd As New SqlCommand
        Try
            connection.Open()
            dataadapter.Fill(ds, "MixerHMI")
            cmd = New SqlCommand(Sql, connection)
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        ' Read the data into the DBTable object
        Dim table As DBTable = New DBTable(cmd.ExecuteReader())
        connection.Close()

        Dim a() As Double = table.getCol(0)
        Dim b() As Double = table.getCol(1)
        Dim c() As Double = table.getCol(2)
        Dim d() As Double = table.getCol(3)
        Dim e() As Double = table.getCol(4)
        Dim f() As Double = table.getCol(5)
        Dim g() As Double = table.getCol(6)
        Dim h() As Double = table.getCol(7)
        Dim i() As Double = table.getCol(8)
    End Sub

NOTE:I put the ReadFromDBtoArray() into dataRateTimer2_Tick event , here is the code:

Private Sub dataRateTimer2_Tick(sender As Object, e As EventArgs) Handles dataRateTimer2.Tick

        Do While nextDataTime < DateTime.Now

            ' After obtaining the new values, we need to update the data arrays.
            If currentIndex >= timeStamps.Length Then
                Dim trimAmount As Integer = (timeStamps.Length + 99) / 100
                Dim i As Integer
                For i = trimAmount To UBound(timeStamps)
                    timeStamps(i - trimAmount) = timeStamps(i)
                    dataSeriesA(i - trimAmount) = dataSeriesA(i)
                    dataSeriesB(i - trimAmount) = dataSeriesB(i)
                    dataSeriesC(i - trimAmount) = dataSeriesC(i)
                    dataSeriesD(i - trimAmount) = dataSeriesD(i)
                    dataSeriesE(i - trimAmount) = dataSeriesE(i)
                    dataSeriesF(i - trimAmount) = dataSeriesF(i)
                    dataSeriesG(i - trimAmount) = dataSeriesG(i)
                    dataSeriesH(i - trimAmount) = dataSeriesH(i)
                    dataSeriesI(i - trimAmount) = dataSeriesI(i)
                Next
                currentIndex -= trimAmount
            End If

            ' Store the new values in the current index position, and increment the index.
            dataSeriesA(currentIndex) = dataA
            dataSeriesB(currentIndex) = dataB
            dataSeriesC(currentIndex) = dataC
            dataSeriesD(currentIndex) = dataD
            dataSeriesE(currentIndex) = dataE
            dataSeriesF(currentIndex) = dataF
            dataSeriesG(currentIndex) = dataG
            dataSeriesH(currentIndex) = dataH
            dataSeriesI(currentIndex) = dataI
            timeStamps(currentIndex) = nextDataTime
            currentIndex += 1

            ' Update nextDataTime. This is needed by our data generator. In real applications,
            ' you may not need this variable or the associated do/while loop.
            nextDataTime = nextDataTime.AddMilliseconds(dataRateTimer.Interval)
        Loop

        ReadFromDBtoArray()
    End Sub

Thanks for your help!
Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-19-2019 12:43
Hi Cici,

From my understanding of your requirement, your "historical data" occurs before the realtime data. So your code should read the historical data first, before starting the time to collect realtime data. I see that you read the historical data repeatedly in the realtime data acquisition code (which is in dataRateTimer2_Tick). Please read your historical data before starting data acquisition.

To plot a line chart, you need the x-coordinates and y-coordinates of the data points. The y-coordinates are in dataSeriesA, ..... dataSeriesI. The x-coordinates are in timeStamps. In your database code, you only read the y-coordinates. Where are the x-coordinates (the timeStamps)?

Suppose your data are the intensity of radioactive decay, which occur at random times. You only provides the intensity values, but not the time when it occurs. So how can we plot the chart?

If due to the nature of your data, you know what are the x-coordinates yourself, you must write code to store the x-coordinates in timeStamps. It is because if you do not tell the program, it cannot know the x-coordinates.

Also, in your ReadFromDBtoArray, I did not see you read any data into dataSeriesA. It only reads into a local variables a, b, c, d, ..... As local variables, they will be destroyed automatically when the ReadFromDBtoArray returns. So it seems your ReadFromDBtoArray does not do anything at all to the data.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-20-2019 01:54
Hi Peter,

Thanks for your quick reply!

1) I will read the historical data before starting data acquisition.

2) How can I define the timeStamps if I want to read 12 historical data?

3) This is the part that I am confused. How can I combine the real time data (dataSeriesA-I) with historical data (a()-i())?

Sorry, I have too many questions.

Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-20-2019 19:11
Hi Cici,

In a realtime chart, the chart plots the data values against time.

For example, if the wind speed at Nov 20, 2019 12:24:56 is 3.2m/s, and the wind speed at Nov 20, 2019 12:25:03 is 4.6 m/s, then there are two data points. One point is at 12:24:56 and the value is 3.2. The other point is 12:25:03 and the value is 4.6.

If you have some historical data, where the wind speed is 1.9. Now you must also include the date/time of that wind speed. We cannot plot the realtime chart with just a data value without the date/time.

The timeStamps are the date/time of your historical data. Each of your data value must be collected at some date/time in the past. Please use that date/time. If you know what the data/time should be, please put that date/time in the timeStamps array.

The dateSeriesA is all your data, both historically and realtime data. Do not read your historical data into a() - i(). Please read your data into dataSeriesA .... If you must read your data into a() - i(), please copy the data to dataSeriesA ....

For example, dataSeriesA has 100000 elements, and you have 12 historical points. Read the 12 points to dataSeriesA(0), dataSeriesA(1), dataSeriesA(2), .... dataSeriesA(11). Then set the currentIndex to 12. Now in the timer tick event, the realtime data will be stored at dataSeriesA(12), dataSeriesA(13), dataSeriesA(14), ......  That means the dataSeriesA will contain your historical data, followed by the realtime data.

Regards
Peter Kwan

  Re: How to set up multiple time range for real time track chart
Posted by Cici on Nov-28-2019 04:23
Hi Peter,

I have some questions,

1) Read historical data before starting data acquisition.

My read historical data event named is ReadFromDBtoArray. Where do I put the ReadFromDBtoArray event? Before or after define the currentIndex?

        currentIndex = 100 '100 data for historical data
        For i = currentIndex To UBound(timeStamps)
            timeStamps(i) = DateTime.MinValue
        Next

2) The original code to define the timeStamps is:

    Private Const sampleSize As Integer = 115200
    Private timeStamps(sampleSize - 1) As Date

Is the same way to define the timeStamps for historical data?

3) Can I email my project code to you? If so, please send email to me. Here is my email address: wangyk.wangx@gmail.com

Thanks,

Cici

  Re: How to set up multiple time range for real time track chart
Posted by Peter Kwan on Nov-29-2019 03:54
Attachments:
Hi Cici,

The currentIndex should be set to the number of data points in your historical data. So the historical data must be read first, so that you know how many historical data points you have, and set the currentIndex accordingly.

The timeStamps is an array to contain the x-coordinates of the data points. The x-coordinates of all the data (both historical and realtime) are stored in the array.

I have just modified the "Realtime Chart with Track Line" sample code attached in one of my previous message in this post, so that it now has "historical data". In the code, the "historical data" are just artificial values. In your real code, please replace the artificial  values with your real data.

Regards
Peter Kwan
vb_realtimetrack_with_historical_data.zip
vb_realtimetrack_with_historical_data.zip

8.63 Kb

  Re: How to set up multiple time range for real time track chart
Posted by Cici Wang on Dec-07-2019 05:50
Hi Peter,

It works!

Thank you so much!

Cici


hausfrauen porno tube