Wish xChart - bar colour based on value

JdV

Active Member
Licensed User
Longtime User
It would be useful if bars could be coloured based on their value.

For example, assuming the max Y value is 100, bars with value 0-49 could be green, 50-74 could be yellow, 75-100 could be red.

Regards

Joe
 

JdV

Active Member
Licensed User
Longtime User
Thanks for the reply.

If anyone else is interested I managed to get a workaround to produce the required effect using a stacked bar chart with three coloured bars:
B4X:
DemoChart.AddBar("Val", Colors.Green) '<-- Add coloured bars
DemoChart.AddBar("Val", Colors.Yellow) '<-- in this order
DemoChart.AddBar("Val", Colors.Red) '<-- for this to work
DemoChart.AddBarMultiplePoint("Value", ChooseColour(val))

I then have a sub named ChooseColour which sizes the three coloured bars depending on 'val':
B4X:
Sub ChooseColour(val As Double) As Double()
    If val >= 75 And val < 85 Then
        Return Array As Double(0,val,0) '<-- Only show the yellow bar
    else if val >= 85 Then
        Return Array As Double(0,0,val) '<-- Only show the red bar
    Else
        Return Array As Double(val,0,0) '<-- Only show the green bar
    End If
End Sub

It's not elegant but it works for me!

Joe
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…