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

Message ListMessage List     Post MessagePost Message

  Chart Disappearing : Streaming Chart
Posted by Venkat on Nov-02-2008 19:01
Imports System.Data
Imports System.Data.SqlClient
Imports ChartDirector
Partial Class Default3
    Inherits System.Web.UI.Page
    Dim command As New SqlCommand
    Public connection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Public ds As New System.Data.DataSet
    Dim s() As String
    Public n As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        GetFillData()
        Timer1.Enabled = True
    End Sub
    Private Sub GetFillData()
        connection.Open()
        Dim comm As String
        Dim iu As Long
        comm = "SELECT top 40 DateStamp,CTime,Speed FROM SampleData where BID='B620' AND DATESTAMP='10/22/2008' ORDER BY CTime"
        Dim command As New SqlCommand(comm, connection)
        Dim Reader As SqlDataReader
        Reader = command.ExecuteReader
        Do While Reader.Read = True
            Dim a1 As String = CStr(Reader("DateStamp")) & "," & Reader("CTime") & "," & Reader("Speed")
            ListBox2.Items.Add(a1)
            iu = iu + 1
        Loop
    End Sub

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
        Timer1.Enabled = False
        ' Draw chart using the most update data
        drawChart(WebChartViewer1)
        Timer2.Enabled = True
        ' If is streaming request, output the chart immediately and terminate the page
        If WebChartViewer.IsStreamRequest(Page) = True Then
           WebChartViewer1.StreamChart()
        End If
    End Sub
    Private Sub drawChart(ByVal viewer As WebChartViewer)
        Dim m As Integer = 0
        Dim n As Integer = 0
        Dim x As Integer = 0
        Dim dataSeries1(14) As Double
        Dim DStamp(14) As Date
        Dim timeStamps(14) As Date
        Try
            If ListBox1.Items.Count > 0 Then
                ListBox1.Items.Clear()
            End If
            For m = x To 14
                ListBox1.Items.Add(ListBox2.Items(m).Text)
                s = Split(ListBox1.Items(m).Text, ",")
                DStamp(m) = s(0)
                timeStamps(m) = s(1)
                dataSeries1(m) = s(2)
            Next
            Dim c As XYChart = New XYChart(600, 270, &HF4F4F4, &H0, 0)
            c.setRoundedFrame()
            c.setPlotArea(55, 62, 520, 175, &HFFFFFF, -1, -1, &HCCCCCC, &HCCCCCC)
            c.setClipping()
            c.addTitle("Speed Chart", "Times New Roman Bold Italic", 15 _
                ).setBackground(&HDDDDDD, &H0, Chart.glassEffect())
            Dim b As LegendBox = c.addLegend2(55, 33, 3, "Arial Bold", 9)
            b.setBackground(Chart.Transparent, Chart.Transparent)
            b.setWidth(520)
            c.yAxis().setTitle("DateStamp", "Arial Bold", 10)
            c.xAxis().setTickDensity(75, 15)
            c.xAxis().setWidth(2)
            c.yAxis().setWidth(2)
            c.xAxis().setLabelFormat("{value|hh:nn:ss}")
            Dim layer As LineLayer = c.addLineLayer2()
            layer.setXData(timeStamps)
            layer.addDataSet(dataSeries1, &HFF0000, c.formatValue(dataSeries1(UBound(dataSeries1)), "Software: <*bgColor=FFCCCC*> {value|2}"))
            WebChartViewer1.Image = c.makeWebImage(Chart.PNG)
            '9Timer2.Enabled = True
        Catch ex As Exception

        End Try
    End Sub
    Protected Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
        Timer2.Enabled = False
        Dim n As Integer
        For n = 0 To 4
            ListBox2.Items.RemoveAt(0)
        Next
        Timer1.Enabled = True
    End Sub

End Class

Peter

what is wrong in my code ? I am trying to display Streaming Chart. And data is coming from database. What I am trying to do, (1) Pulling data 500 records from database and adding to listbox. (2) Added two Ajax Timers. (timer1 will add some 40 records to listbox2 at 2 seconds interval and same time it adds those values to Arrarys to send to the chart for display) Timer2 delete those 40 records from listbox1.

When ever possible please let me know.

thanks

venkat

  Re: Chart Disappearing : Streaming Chart
Posted by Peter Kwan on Nov-03-2008 01:47
Hi Venkat,

It seems your code is not using streaming update at all. It is usually ASP.NET AJAX update. As your code is not using streaming update, it should not send a streaming response back. The "IsStreamRequest" method is always false.

Note the server must send back the proper response to the browser, otherwise the browser will not understand the response. For example, if the browser asks for an ASP.NET AJAX update, your code must send an ASP.NET AJAX response back, not streaming chart update. The ASP.NET AJAX does not support streaming charts. You can only use streaming charts if the browser issues a stream update request.

In ASP.NET AJAX, you may just redraw the chart, like:

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
     Timer1.Enabled = False
     drawChart(WebChartViewer1)
     Timer2.Enabled = True
End Sub

If the above still does not solve the problem, I suggest you perform the following steps to diagnose the problem:

(a) Check if your timers are working. For example, you may set breakpoints to see if the breakpoints are reached.

(b) Remove the "Try/Catch" block. In your case, the "Try/Catch" block does not seem to have any useful purpose. It can only hide the errors, causing the code different to trouble-shoot. (The "Try/Catch" block should only be used if there are errors not under your control - such as I/O errors due to disk or network failure. It should never be used to hide errors in the code itself.)

(c) You may use the following addTitle line:

c.addTitle("" + DateTime.Now.Ticks);

The above will print the latest ticks on the chart title, so you can see if it is updating or not.

Hope this can help.

Regards
Peter Kwan