I've created a line chart with data from a SQLite table. It was startlingly easy (Thank you Erel)!
One slight problem; it is slightly - just slightly - wider than the canvas, running over the right margin.
How can I get it to fit nicely, like the sine and cosine example in the tutorial, from which I got the code.
I do have lots of points - over two thousand. See code and image.
Thanks for any suggestions.
One slight problem; it is slightly - just slightly - wider than the canvas, running over the right margin.
How can I get it to fit nicely, like the sine and cosine example in the tutorial, from which I got the code.
I do have lots of points - over two thousand. See code and image.
Thanks for any suggestions.
B4X:
Sub CreateLineChart( sessionid As String )
DateTime.DateFormat = "MMM dd"
Dim LD As LineData
LD.Initialize
LD.Target = panel1
Dim fTemp = 0 As Float
Dim minTemp = 9999 As Float
Dim maxTemp = 0 As Float
Dim cur As Cursor
cur = Main.SQL1.ExecQuery("SELECT when_sampled, temp_f FROM sample"
Dim xInterval = Floor( cur.RowCount / 6 )
Charts.AddLineColor(LD, Colors.Red)
For i = 0 To cur.RowCount - 1
cur.Position = i
fTemp = code.CFloat( cur.GetDouble2(1) )
Charts.AddLinePoint(LD, DateTime.Date( DateUtils.UnixTimeToTicks( cur.GetLong2(0) ) ), fTemp, i Mod xInterval = 0)
If fTemp < minTemp Then
minTemp = fTemp
End If
If fTemp > maxTemp Then
maxTemp = fTemp
End If
Next
Dim G As Graph
G.Initialize
G.Title = "Ocean Temperatures"
G.XAxis = "Date"
G.YAxis = "Temps Fahrenheit"
G.YStart = Floor( minTemp / 10 ) * 10
G.YEnd = Ceil( maxTemp / 10 ) * 10
G.YInterval = 10
G.AxisColor = Colors.Black
Charts.DrawLineChart(G, LD, Colors.White)
End Sub