Android Question How to create a dynamic array for xChart?

ThePuiu

Active Member
Licensed User
Longtime User
I have a variable number of Switch buttons. Each is associated with a size that will be graphically represented in an xChart. The user can switch one or more buttons. I want to know how I could dynamically create the necessary Array for xChart data feed. Used code is:
B4X:
Dim MenuItems As List
MenuItems = m.Get("ListOfValues")
For i = 0 To MenuItems.Size - 1
    m = MenuItems.Get(i)                   
    LineChart2.AddLineMultiplePoints(m.Get("Moment"), Array As Double(m.Get("v1"),...... m.Get("vX")), i Mod 90 = 0)
Next

The ListOfValues list always contains only the values that will be displayed (if the user selects the first, second and fifth buttons, the list will contain "Moment", "v1", "v2" and "v5").
For a small number of variants can be written with Switch but if the number of variants is larger I do not think it is an elegant solution.
Thank you!
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
A clunky solution would be to loop through your list & put the points into a Double array:
B4X:
Private MenuItems As List
MenuItems = m.Get("ListOfValues")

Private points(MenuItems.Size - 1) as Double

For i = 1 to MenuItems.Size - 1
    points(i) = MenuItems.Get(i)
Next
LineChart2.AddLineMultiplePoints(m.Get("Moment"), points, i Mod 90 = 0)

Untested...

- Colin.
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
Nope...
B4X:
Cannot parse: (read only map) {
    Moment = "26/12/2019 00:47:00";
    v1 = 28;
    v2 = 19;
}
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim MenuItems As List = m.Get("ListOfValues")
For i = 0 To MenuItems.Size - 1
    m = MenuItems.Get(i)  
    Dim Temp As List
    Temp.Initialize
    For i = 1 To X
      If Switch(i - 1).Checked Then Temp.Add(m.Get("v" & i))
    Next
   Dim arr(Temp.Size) As Double
   For ii = 0 To Temp.Size - 1
     arr(ii) = Temp.Get(ii)
  Next
    LineChart2.AddLineMultiplePoints(m.Get("Moment"), arr, i Mod 90 = 0)
Next
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
it is a minor escape, obviously, I have corrected it. The code is fully functional but unfortunately the execution time is very long (18 seconds for a set of 720 values)

What I want to do:
the user can choose which values to be represented graphically by a variable number of switches (the graph is generated for a device - at user choice, which records between 1 and 10 sizes.)
 

Attachments

  • graph.jpg
    graph.jpg
    58.8 KB · Views: 186
Upvote 0
Top