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

Message ListMessage List     Post MessagePost Message

  realtime chart using asp.net data array temporary storage
Posted by ramil on Sep-29-2017 10:08
hi sir peter,

Would like to request your help regarding my realtime chart using asp.net.
The problem is i cannot hold the data array storage with the past values for the duration of 5 minutes. the data i got from the data aquisition of i/o device. upon changing the value, the whole chart data is changed also with the recent one.. you can see the graph is plotting only a straight line leaving the previous data overwritten. please see attached my chart and the code for you to evaluate.. your help is highly needed for this project. Thank you in advance..

regards

  Re: realtime chart using asp.net data array temporary storage
Posted by Peter Kwan on Sep-29-2017 18:15
Hi ramil,

For some reason, I cannot see your attached chart and the code. Would you mind to upload it once more? In the "File to Upload" field, you can choose a file, then press the "Send File" button. The file will then be uploaded. Note that the file size should not exceed 250 Kbytes. If you cannot upload the file, you can email me at pkwan@advsofteng.net

Would you mind to clarify what kind of "temporary storage" you are using?

In ASP.NET, you can use a session variable as the temporary storage. Is this what you are using? This is a short example:


// This is the "temporary storage"
List<double> myData = (List<double>)Session["myData"];
if (null == myData)
    Session["myData"] = myData = new List<double>();

// Add some value to the "temporary storage"
myData.Add(newDataValue);

// The data array can be then used to plot chart
double[] myDataArray = myData.ToArray();


*** NOTE ***: The above is not related to ChartDirector. It is just standard ASP.NET code to store information. You may need to refer to ASP.NET documentation for more details.


Regards
Peter Kwan

  Re: realtime chart using asp.net data array temporary storage
Posted by ramil on Oct-03-2017 08:25
Attachments:
hi sir peter,

appreciate very much with your soonest response.. I am resending the files for you evaluation regarding temporary session variables in asp.net.. I also included your sample realtime chart with i modified in the data acquisition portion only.. hope you can provide me a sample working code in plotting a realtime chart in asp.net session.

thank you and more power..
realtime.txt
Private Sub drawChart(ByVal viewer As WebChartViewer)
                '
        ' Data to draw the chart. In this demo, the data buffer will be filled by a random data
        ' generator. In real life, the data is probably stored in a buffer (eg. a database table, a text
        ' file, or some global memory) and updated by other means.
        '

        ' We use a data buffer to emulate the last 300 samples.
        Dim sampleSize As Integer = 300
        Dim dataSeries1(sampleSize - 1) As Double
        Dim dataSeries2(sampleSize - 1) As Double
        Dim dataSeries3(sampleSize - 1) As Double
        Dim dataSeries4(sampleSize - 1) As Double
        Dim dataSeries5(sampleSize - 1) As Double
        Dim dataSeries6(sampleSize - 1) As Double
        Dim dataSeries7(sampleSize - 1) As Double
        Dim dataSeries8(sampleSize - 1) As Double
        Dim timeStamps(sampleSize - 1) As Date

        ' Our pseudo random number generator
        Dim firstDate As Date = DateTime.Now.AddSeconds(-timeStamps.Length)
        Dim i As Integer
        For i = 0 To UBound(timeStamps)
            timeStamps(i) = firstDate.AddSeconds(i)
            Dim p As Double = timeStamps(i).Ticks / 10000000

            'dataSeries1(i) = Math.Cos(p * 7 * 18463) * 10 + 1 / (Math.Cos(p) * Math.Cos(p) + 0.01) + 20
            'dataSeries2(i) = 100 * Math.Sin(p / 27.7) * Math.Sin(p / 10.1) + 150
            'dataSeries3(i) = 100 * Math.Cos(p / 6.7) * Math.Cos(p / 11.9) + 150

            dataSeries1(i) = PPlant_Tag(34)
            dataSeries2(i) = PPlant_Tag(35)
            dataSeries3(i) = PPlant_Tag(32)
            dataSeries4(i) = PPlant_Tag(33)
            dataSeries5(i) = PPlant_Tag(30)
            dataSeries6(i) = PPlant_Tag(31)
            dataSeries7(i) = PPlant_Tag(28)
            dataSeries8(i) = PPlant_Tag(29)

        Next i

        ' Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4) background, black
        ' (000000) border, 1 pixel raised effect, and with a rounded frame.
        Dim c As XYChart = New XYChart(560, 485, &HF4F4F4, &H0, 0)
        c.setRoundedFrame()

        ' Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff) background.
        ' Enable both horizontal and vertical grids by setting their colors to grey (cccccc). Set
        ' clipping mode to clip the data lines to the plot area.
        c.setPlotArea(55, 92, 480, 350, &HFFFFFF, -1, -1, &HCCCCCC, &HCCCCCC)
        c.setClipping()

        ' Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light grey
        ' (dddddd) background, black (000000) border, and a glass like raised effect.
        'c.addTitle("Realtime Trend", "Times New Roman Bold ", 12 _
        '   ).setBackground(&HDDDDDD, &H0, Chart.glassEffect())

        ' Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the legend box
        ' to the same width as the plot area and use grid layout (as opposed to flow or top/down
        ' layout). This distributes the 3 legend icons evenly on top of the plot area.
        Dim b As LegendBox = c.addLegend2(36, 27, 4, "Arial Bold", 9)
        b.setBackground(Chart.Transparent, Chart.Transparent)
        b.setWidth(520)

        ' Configure the y-axis with a 10pts Arial Bold axis title
        c.yAxis().setTitle("Value (um pp)", "Arial", 9)

        ' Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15 pixels
        ' between minor ticks. This shows more minor grid lines on the chart.
        c.xAxis().setTickDensity(75, 15)

        ' Set the axes width to 2 pixels
        c.xAxis().setWidth(2)
        c.yAxis().setWidth(2)

        ' 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()

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

        ' The 3 data series are used to draw 3 lines. Here we put the latest data values as part of the
        ' data set name, so you can see them updated in the legend box.
        layer.addDataSet(dataSeries1, &HFF0000, c.formatValue(dataSeries1(UBound(dataSeries1)), "VR1014X: <*bgColor=FFCCCC*> {value|2} "))
        layer.addDataSet(dataSeries3, &HFF, c.formatValue(dataSeries3(UBound(dataSeries3)), "VR1013X: <*bgColor=CCCCFF*> {value|2} "))
        layer.addDataSet(dataSeries5, &HCC00, c.formatValue(dataSeries5(UBound(dataSeries5)), "VR1007X: <*bgColor=CCFFCC*> {value|2} "))
        layer.addDataSet(dataSeries7, &HFF0000, c.formatValue(dataSeries7(UBound(dataSeries7)), "VR1005X: <*bgColor=FFCCCC*> {value|2} "))

        layer.addDataSet(dataSeries2, &HCC00, c.formatValue(dataSeries2(UBound(dataSeries2)), "VR1014Y: <*bgColor=CCFFCC*> {value|2} "))
        layer.addDataSet(dataSeries4, &HFF0000, c.formatValue(dataSeries4(UBound(dataSeries4)), "VR1013Y: <*bgColor=FFCCCC*> {value|2} "))
        layer.addDataSet(dataSeries6, &HFF, c.formatValue(dataSeries6(UBound(dataSeries6)), "VR1007Y: <*bgColor=CCCCFF*> {value|2} "))
        layer.addDataSet(dataSeries8, &HCC00, c.formatValue(dataSeries8(UBound(dataSeries8)), "VR1005Y: <*bgColor=CCFFCC*> {value|2} "))
       
        ' output the chart
        WebChartViewer1.Image = c.makeWebImage(Chart.PNG)

    End Sub
realtime_code_pix.png
realtime_web_chart.png

  Re: realtime chart using asp.net data array temporary storage
Posted by Peter Kwan on Oct-03-2017 21:06
Hi ramil,

For web applications, normally for realtime charts the data are collected by a background process, not using ASP.NET.

For example, when you access a realtime stock chart, the moment you browser access the realtime web site, you will see some recent prices and new prices are added in realtime. This proves that the data are not collected by the web page, because it includes recent prices that occur before you access the web site. If you close the browser and then reconnect later, you will not lose any data. This shows that the web server will collect the data event if no one is looking at the web site.

For such type of system, normally there is background process to collect data and store them into a database. The web page just displays the latest data from the database.

Our original ASP.NET realtime chart sample code is assuming this type of realtime chart system. Instead of using a database, it uses random data. In real application, it is expected you replace the random code with database code, where the database is updated in realtime by the background process.

If you want the ASP.NET web page to collect the data and append to the arrays, you cannot use the same sample code which uses local variables and does not store the data. (The data are stored in the realtime database.) Instead, you have to modify the code to use session variables as mentioned in my last message. The following is an example:


'
' Draw the chart
'
Private Sub drawChart(viewer As WebChartViewer)

    Dim sampleSize As Integer = 240

    ' Use session variables for data storage
    If IsNothing(Session("timeStamps")) Then
        Session("timeStamps") = New System.Collections.Generic.List(Of Date)()
        Session("dataSeries1") = New System.Collections.Generic.List(Of Double)()
    End If
    Dim dataSeries1 As System.Collections.Generic.List(Of Double) = Session("dataSeries1")
    Dim timeStamps As System.Collections.Generic.List(Of Date) = Session("timeStamps")

    ' Remove old data points to avoid accumulation of infinite number of points
    If timeStamps.Count >= sampleSize Then
        timeStamps.RemoveRange(0, timeStamps.Count - sampleSize + 1)
        dataSeries1.RemoveRange(0, dataSeries1.Count - sampleSize + 1)
    End If

    ' Add a new data point
    timeStamps.Add(DateTime.Now)
    Dim p As Double = DateTime.Now.Ticks / 10000000
    dataSeries1.Add(100 * Math.Sin(p / 27.7) * Math.Sin(p / 10.1) + 150)

    ' Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4) background, black
    ' (000000) border, 1 pixel raised effect, and with a rounded frame.
    Dim c As XYChart = New XYChart(600, 270, &Hf4f4f4, &H000000, 0)
    c.setRoundedFrame()

    ' Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff) background.
    ' Enable both horizontal and vertical grids by setting their colors to grey (cccccc). Set
    ' clipping mode to clip the data lines to the plot area.
    c.setPlotArea(55, 62, 520, 175, &Hffffff, -1, -1, &Hcccccc, &Hcccccc)
    c.setClipping()

    ' Add a title to the chart using 15pt Times New Roman Bold Italic font, with a light grey
    ' (dddddd) background, black (000000) border, and a glass like raised effect.
    c.addTitle("Field Intensity at Observation Satellite", "Times New Roman Bold Italic", 15 _
        ).setBackground(&Hdddddd, &H000000, Chart.glassEffect())

    ' Add a legend box at the top of the plot area with 9pt Arial Bold font. We set the legend box
    ' to the same width as the plot area and use grid layout (as opposed to flow or top/down
    ' layout). This distributes the 3 legend icons evenly on top of the plot area.
    Dim b As LegendBox = c.addLegend2(55, 33, 3, "Arial Bold", 9)
    b.setBackground(Chart.Transparent, Chart.Transparent)
    b.setWidth(520)

    ' Configure the y-axis with a 10pt Arial Bold axis title
    c.yAxis().setTitle("Intensity (V/m)", "Arial Bold", 10)

    ' Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15 pixels
    ' between minor ticks. This shows more minor grid lines on the chart.
    c.xAxis().setTickDensity(75, 15)

    ' Minimum axis scale 240 seconds
    If DateTime.Now.Subtract(timeStamps(0)).TotalSeconds < 240 Then
        c.xAxis().setDateScale(timeStamps(0), timeStamps(0).AddSeconds(240))
    End If

    ' Set the axes width to 2 pixels
    c.xAxis().setWidth(2)
    c.yAxis().setWidth(2)

    ' 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()

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

    ' The 3 data series are used to draw 3 lines. Here we put the latest data values as part of the
    ' data set name, so you can see them updated in the legend box.
    layer.addDataSet(dataSeries1.ToArray(), &Hff0000, c.formatValue(dataSeries1(dataSeries1.Count - 1), _
        "Alpha: <*bgColor=FFCCCC*> {value|2}"))

    ' Output the chart
    viewer.Image = c.makeWebImage(Chart.PNG)

End Sub


Regards
Peter Kwan

  Re: realtime chart using asp.net data array temporary storage
Posted by ramil on Oct-06-2017 09:25
hi sir peter,

thank you so much with your support.. it was amazing.. i'm using the code you provided for storing temporary variables using session in asp.net and it really works..

more power... thank you