### Charts Framework in real time

The Charts Frameworks as provided for
B4A: http://www.b4x.com/android/forum/threads/android-charts-framework.8260/#content
B4J: http://www.b4x.com/android/forum/threads/charts-framework.34710/
can be used for real time data.
When doing so, it is advisable to freeup memory when creating the charts.
Based on the usage of the linechart, add following line in the own sub CreateLineChart:
B4J
'Important to remove all nodes from the pane holding the chart - if not done a memory exception occurs after 200 - 300 scans
ap.RemoveAllNodes
B4J Example Sub to create a dynamic LineChart
`Sub CreateLineChart(ap As AnchorPane, data As List, title As String, xaxislegend As String, yaxislegend As String, YRange As Float, YInterval As Float )
'Important to remove all nodes from the pane holding the chart - if not done a memory exception occurs after 200 - 300 scans
ap.RemoveAllNodes
Dim cvs As Canvas
cvs.Initialize("")
ap.AddNode(cvs, 0, 0, ap.PrefWidth, ap.PrefHeight)
Dim LD As LineData
LD.Initialize
LD.Canvas = cvs
Charts.AddLineColor(LD, fx.Colors.Red)
Dim YMin As Float = 0
Dim YMax As Float = 0
Dim YCur As Float = 0
'Add the datapoints to the chart and determine min/max y range
For i = 0 To data.Size - 1
'Split the dataentry into time and value
Dim s() As String = Regex.Split("=", data.Get(i))
Charts.AddLinePoint(LD, s(0), s(1), True)
YCur = s(1)
If i = 0 Then
YMin = YCur
YMax = YCur
End If
If YCur < YMin Then YMin = YCur
If YCur > YMax Then YMax = YCur
Next
Dim G As Graph
G.Initialize
G.title = title
G.xaxis = xaxislegend
G.yaxis = yaxislegend
'Fixed Y scale - but can also do dynamic scale around the current airpressure
'G.YStart = 900.00
'G.YEnd = 1100.00
'Dynamic scale example would be like
G.YStart = YMin - YRange
G.YEnd = YMax + YRange
'
G.YInterval = YInterval
G.AxisColor = fx.Colors.Black
Charts.DrawLineChart(G, LD, fx.Colors.White)
End Sub`
B4A
'Important to remove all views from the pane holding the chart - if not done a memory exception occurs after 200 - 300 scans
If ap.IsInitialized Then ap.RemoveAllViews
B4A Example Sub to create a dynamic LineChart
`Sub CreateLineChart(ap As Panel, data As List, title As String, xaxislegend As String, yaxislegend As String, YRange As Float, YInterval As Float )
If ap.IsInitialized Then ap.RemoveAllViews
Dim p As Panel
p.Initialize("")
ap.AddView(p, 5%x, 0, 95%x, 100%y - 10dip)
'TabHost1.AddTab2("Line Chart", p)
Dim LD As LineData
LD.Initialize
LD.Target = ap
Charts.AddLineColor(LD, Colors.Red)
Dim YMin As Float = 0
Dim YMax As Float = 0
Dim YCur As Float = 0
'Add the datapoints to the chart and determine min/max y range
For i = 0 To data.Size - 1
'Split the dataentry into time and value
Dim s() As String = Regex.Split("=", data.Get(i))
Charts.AddLinePoint(LD, s(0), s(1), True)
YCur = s(1)
If i = 0 Then
YMin = YCur
YMax = YCur
End If
If YCur < YMin Then YMin = YCur
If YCur > YMax Then YMax = YCur
Next
Dim G As Graph
G.Initialize
G.title = title
G.xaxis = xaxislegend
G.yaxis = yaxislegend
'Fixed Y scale - but can also do dynamic scale around the current airpressure
'G.YStart = 900.00
'G.YEnd = 1100.00
'Dynamic scale example would be like
G.YStart = YMin - YRange
G.YEnd = YMax + YRange
'
G.YInterval = YInterval
G.AxisColor = Colors.Black
Charts.DrawLineChart(G, LD, Colors.White)
End Sub`

Changed: , Category: Charts, File: T6C170M1244.htm, ID: 1244