11
« on: October 15, 2014, 08:03:06 AM »
I'm developing my applications based on AdvancedHMI, which includes a great amount of coding. Since my first touch with Visual Basic was trough AdvancedHMI, I'm still battling difficulties of writing a good code in this language. So, I would like to open this topic, which could cover some more general issues, when upgrading your own AdvancedHMI code.
As I stated in my other posts, my application logs data to excel file on a time basis. On one of my forms I have a chart, where this data should be plotted. Data is plotted by pressing a button, next to the chart. Code for the Plot button, where I read data from excel file and fill the chart series, is:
Private Sub plot_Click(sender As Object, e As EventArgs) Handles iscrtaj.Click
For i As Integer = 900 To 910
Chart1.Series("Nivo VS").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("C" + CStr(i)).Value / 100)
Chart1.Series("Nivo CS").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("D" + CStr(i)).Value / 100)
Chart1.Series("Tlak CS").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("E" + CStr(i)).Value)
Chart1.Series("Protok CS").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("F" + CStr(i)).Value)
Chart1.Series("Struja CS").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("G" + CStr(i)).Value)
Chart1.Series("Želj. protok").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("H" + CStr(i)).Value)
Chart1.Series("Snaga UV").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("I" + CStr(i)).Value)
Chart1.Series("N. uklj. T1").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("J" + CStr(i)).Value / 100)
Chart1.Series("N. isklj. T1").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("K" + CStr(i)).Value / 100)
Chart1.Series("N. uklj. T2").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("L" + CStr(i)).Value / 100)
Chart1.Series("N. isklj. T2").Points.AddXY(excel.Range("B" + CStr(i)).Value, excel.Range("M" + CStr(i)).Value / 100)
Next
End Sub
B column contains data and time, other columns are data. Counter "i" is now set to fixed values, later I plan to implement to plot data according to date picker.
My problem is, plotting this way is SLOW (can't stress this hard enough). When pressing the button, plotting is performed with a speed of 1 - 2 data point per second. I log data every minute, and should be able to chart data for several days, which comes to >10000 data points per series and I have 11 series in chart. What can I do to speed up the plotting?