Android Question Barcharts

peggjones

Active Member
Licensed User
Longtime User
Could someone do me a really big favour and point me to the bit of the code in the example below that actually sets the height of the bars. Many thanks I'm new to this sort of thing and don't fancy spending ages trying to work it out!

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 AsPanel
p.Initialize("")
pnlBars.Initialize("pnlBars")
p.AddView(pnlBars, 0, 0, 95%x, 100%y - 100dip)
TabHost1.AddTab2("Bars Chart", p)
Dim BD AsBarData
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 = 1To4
Charts.AddBarPoint(BD, 2005 + i, ArrayAsFloat(Rnd(0, 1000), Rnd(0, 1000), Rnd(0, 1000)))
Next
Dim G AsGraph
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
 

klaus

Expert
Licensed User
Longtime User
In this line:
B4X:
Charts.AddBarPoint(BD, 2005 + i, Array As Float(Rnd(0, 1000), Rnd(0, 1000), Rnd(0, 1000)))
The height of the columns is defined in
Array As Float(Rnd(0, 1000), Rnd(0, 1000), Rnd(0, 1000))
In the example for each X value there are three columns because the Array contains three values.
Rnd(0, 1000) sets a random value between 0 and 999.

What kind of data do you have and where does it come from ?

Best regards.
 
Upvote 0

peggjones

Active Member
Licensed User
Longtime User
Thanks, I didn't understand than rnd meant random number generation. I have stock prices held in a sql database and I want to present them in a bar chart.

Many thanks.
 
Upvote 0
Top