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


cix porn hard porn kostenlose porn amateur xxx love porn amateur sex hd porn free 3 xxx moblie porn