yhooithin05

Fusion Time chart extract data from database taking long time

Recommended Posts

Hi,

I am using fusion time with vb.net and MySQL database to populate the time series chart, i would like to allow user to pick desired date within 5 weeks on the custom range selector (calendar control), and i am using for loop at the back end to retrieve the  huge data from database so it definitely will consume long time to render the chart (around 1 minute),  just want to ask any advise if any other method to populate the json string to load the chart in fast? Thanks!

Using client As WebClient = New WebClient()
            schema = ("[{name:'SensorName',type:'string'}, {name: 'Time',type:'date', format:'%Y-%m-%d %H:%M:%S %p'}, {name:'Particle Counter Value',type:'number'}] ")
            selectPCounter = " SELECT * FROM tbtestdata where sampledate >= '2020-12-24' AND sampledate <= '2021-01-27' "
            Dim dt As New DataTable
            dt = conn.query(selectPCounter)
            If dt.Rows.Count > 0 Then
                data.Append("[")
                For i As Integer = 0 To dt.Rows.Count - 1
                    If i <> dt.Rows.Count - 1 Then
                        data.Append("['" + dt.Rows(i)("SensorName").ToString + "','" + dt.Rows(i)("SampleDate").ToString + " " + dt.Rows(i)("SampleTime").ToString + "'," +
                            "'" + dt.Rows(i)("SampleValue").ToString + "'],")
                    Else
                        data.Append("['" + dt.Rows(i)("SensorName").ToString + "','" + dt.Rows(i)("SampleDate").ToString + " " + dt.Rows(i)("SampleTime").ToString + "'," +
                            "'" + dt.Rows(i)("SampleValue").ToString + "']]")
                    End If

                Next
            End If
        End Using

        Dim fusionTable As FusionTable = New FusionTable(schema, data.ToString)
        Dim timeSeries As TimeSeries = New TimeSeries(fusionTable)
        timeSeries.AddAttribute("caption", "{ text:'Particle Counter' }")
        timeSeries.AddAttribute("subcaption", "{text:'Daily'}")
        timeSeries.AddAttribute("chart", "{exportEnabled:'1'}")
        timeSeries.AddAttribute("yAxis", "[{plot: {value:  'Particle Counter Value',type:'line'},title:  'PC', series:  'SensorName' }]")

        Dim chart As Chart = New Chart("timeseries", "first_chart", "1600", "700", "json", timeSeries)
        ltChart.Text = chart.Render()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now