B4J Library [B4X] [XUI] xChartLite b4xlib

mcqueccu

Well-Known Member
Licensed User
Longtime User
Here is an example. I use AddBarPointData but it and I also get the same color

B4X:
Private Sub CreateBarData
    ' clear previous data
    BarChart1.ClearData

    ' add the bars
    BarChart1.AddBar("Bar 1", xui.Color_Red)
    BarChart1.AddBar("Bar 2", xui.Color_Blue)
    BarChart1.AddBar("Bar 3", xui.Color_Green)
    BarChart1.AddBar("Bar 4", xui.Color_Yellow)
    BarChart1.AddBar("Bar 5", xui.Color_Magenta)

    ' add the items
    For i = 1 To 5
        BarChart1.AddBarPointData("Bar " & i,Rnd(0,500))
    Next
   
    ' draw the chart
    BarChart1.DrawChart
End Sub
 

Attachments

  • xCharlite_Bar.zip
    2.8 KB · Views: 265

Ishmael

Member
Yes please thats how i did it
 

klaus

Expert
Licensed User
Longtime User
What exactly do you want to display ?
When you have more than one bar you must use AddBarMultipoints like below.

B4X:
    For i = 1 To 5
'        BarChart1.AddBarPointData("Bar " & i,Rnd(0,500))
        BarChart1.AddBarMultiplePoint(i, Array As Double(Rnd(0,500), Rnd(0,500), Rnd(0,500), Rnd(0,500), Rnd(0,500)))
    Next

And you get this:



Or you can get this with only 1 point, the single line below instead of the For / Next loop:
B4X:
    BarChart1.AddBarMultiplePoint("", Array As Double(Rnd(0,500), Rnd(0,500), Rnd(0,500), Rnd(0,500), Rnd(0,500)))

 

Ishmael

Member
I want single Bars with different colors eg. Different Animals on the X-Axis, with different labels. Using Multipoint puts them together in your example without individual x-labels

I want Something like this




Using multipoint, it means I have to put the places i don't want to 0,0 like this, which is not really pretty

I wish the Addbarpointdata can use the individual colors in the set in the Add bar

B4X:
Private Sub CreateBarData
    ' clear previous data
    BarChart1.ClearData

    ' add the bars
    BarChart1.AddBar("Rabbit", xui.Color_Red)
    BarChart1.AddBar("Cat", xui.Color_Blue)
    BarChart1.AddBar("Dog", xui.Color_Green)
    BarChart1.AddBar("Goldfish", xui.Color_Yellow)
    BarChart1.AddBar("Hamster", xui.Color_Magenta)
    
    'Workaround (Set it manually) not pretty
    BarChart1.AddBarMultiplePoint("Rabbit", Array As Double(Rnd(0,500),0, 0, 0, 0))
    BarChart1.AddBarMultiplePoint("Cat", Array As Double(0,Rnd(0,500), 0, 0, 0))
    BarChart1.AddBarMultiplePoint("Dog", Array As Double(0,0, Rnd(0,500), 0, 0))
    BarChart1.AddBarMultiplePoint("Goldfish", Array As Double(0,0, 0,Rnd(0,500), 0))
    BarChart1.AddBarMultiplePoint("Hamster", Array As Double(0,0, 0, 0, Rnd(0,500)))

    
    ' draw the chart
    BarChart1.DrawChart
End Sub

 

Ishmael

Member
I switched to the Xcharlite.bas Class File and I modified the DrawBars Sub and it's working.
But its affecting the AddBarMultipoint which i dont use/need at the moment


B4X:
    If Graph.GradientColors = False Then
   xcvsGraph.DrawRect(r, Cols(i), True, 1dip)    'Changed the cols(j) to cols(i)' to loop through the colors set using addbar in itemdata type
 Else

Result

 

Tecuma

Member
Licensed User
I made several tests with several values for x-axis and y-axis. I saw that there is a scaling.
I do not know how many values the users will create. Will there be a certain amount of values where scaling will not show an optical good result?
What would be the best way to handle such a situation? Is it possible to disable scaling and enable scrolling at a certain amount of values?
 

klaus

Expert
Licensed User
Longtime User
What kind of chart are you speaking of?
To give a concrete answer you need give some more details on what exactly you want to do.
In the xChartLite library there is no zoom nor scroll function.
The xChart library has a zoom function. Depending on the number of values you could activate it or not.
Do you have any concrete example?
 

Tecuma

Member
Licensed User
I am creating the graph with values from a DB. Example:



Here we have 11 values (X axis). What is when I have 100 entries or more? I am not sure if this will be shown properly and readable. That is why I asked if scrolling is possible.
 

Di3e

New Member
Hi Klaus, Thanks for sharing the library, I want to get the y index value of the lines when the EventName_CursorTouch(Action As Int, CursorPointIndex As Int) routine is fired, how do I do that?

best regards
 

klaus

Expert
Licensed User
Longtime User
The xChartLite libary has been updated to Version 1.6
Added check of chart incompatibilities
Amended problem with DisplayValues and DisplayValuesOnHover
Added GetMaxNumberBars2, does not need to know the data values.
Set Items and Points lists as Public
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…