Android Question Line Chart overruns x-axis

doncx

Active Member
Licensed User
Longtime User
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.

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
 

Attachments

  • charttoowide.jpg
    charttoowide.jpg
    127.7 KB · Views: 221

klaus

Expert
Licensed User
Longtime User
One slight problem; it is slightly - just slightly - wider than the canvas, running over the right margin.
What exactly do you mean with this ?
Especially with this 'running over the right margin' ?
I noticed that when the last item is not on a tick the last vertical line is not drawn, is this what you are asking for ?
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
How is panel1 added to the layout?
Panel1 is added through the designer, which has the following code in it's script:
B4X:
Panel1.Height = 100%y - 230dip
Panel1.Width = 100%x
Panel1.Top = 150dip
Panel1.Left = 0
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
What exactly do you mean with this ?
Especially with this 'running over the right margin' ?
I noticed that when the last item is not on a tick the last vertical line is not drawn, is this what you are asking for ?
I meant that the appearance is that the right border is pushed off the screen, but I think you may be on to it. The last plotted point may not have an associated x-axis label tick. Thanks for the suggestion.
 
Upvote 0

doncx

Active Member
Licensed User
Longtime User
What exactly do you mean with this ?
Especially with this 'running over the right margin' ?
I noticed that when the last item is not on a tick the last vertical line is not drawn, is this what you are asking for ?
That was it! Thanks for the advice, Klaus. Good call.
 
Upvote 0
Top