Hello,
I have been reading through the SQLite Tutorial and the Charts Framework tutorial.
What I'd like to do is combine the two - pull the data out of the database and into a barchart. So I have created a table called "Orders" in a database called 1.db. There are three column names: "Id", "month" and "sales"
I want to populate the bar chart with "month" and "sales"
The Sub code from your bar chart example is:
I assume I need to replace the following code with some code that would pull in the data from my database.
If anyone is able to give me a quick pointer (or example of how I would populate the data from the database example) I would be very grateful.
I'm guessing I would need to use ExecQuery but can't work out quite how to do it.
Thank You
I have been reading through the SQLite Tutorial and the Charts Framework tutorial.
What I'd like to do is combine the two - pull the data out of the database and into a barchart. So I have created a table called "Orders" in a database called 1.db. There are three column names: "Id", "month" and "sales"
I want to populate the bar chart with "month" and "sales"
The Sub code from your bar chart example is:
B4X:
Sub CreateBarsTab
'It is not possible to draw directly on the panel that acts as the Tab page.
'This panel doesn't have an absolute size as its size changes to fit the TabHost available size.
'For that reason we add a panel to a panel.
Dim p As Panel
p.Initialize("")
pnlBars.Initialize("pnlBars")
p.AddView(pnlBars, 0, 0, 95%x, 100%y - 100dip)
TabHost1.AddTab2("Bars Chart", p)
Dim BD As BarData
BD.Initialize
BD.Target = pnlBars
BD.BarsWidth = 15dip
BD.Stacked = False
Charts.AddBarColor(BD, MakeTransparent(Colors.DarkGray, 230)) 'First bar color
Charts.AddBarColor(BD, MakeTransparent(Colors.Gray, 230))
Charts.AddBarColor(BD, MakeTransparent(Colors.LightGray, 230))
For i = 1 To 4
Charts.AddBarPoint(BD, 2005 + i, Array As Float(Rnd(0, 1000), Rnd(0, 1000), Rnd(0, 1000)))
Next
Dim G As Graph
G.Initialize
G.Title = "Bars Chart"
G.XAxis = "Year"
G.YAxis = "Values"
G.YStart = 0
G.YEnd = 1000
G.YInterval = 100
G.AxisColor = Colors.Black
Charts.DrawBarsChart(G, BD, Colors.White)
End Sub
I assume I need to replace the following code with some code that would pull in the data from my database.
B4X:
For i = 1 To 4
Charts.AddBarPoint(BD, 2005 + i, Array As Float(Rnd(0, 1000), Rnd(0, 1000), Rnd(0, 1000)))
Next
If anyone is able to give me a quick pointer (or example of how I would populate the data from the database example) I would be very grateful.
I'm guessing I would need to use ExecQuery but can't work out quite how to do it.
Thank You