ThePuiu Active Member Licensed User Longtime User Dec 26, 2019 #1 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!
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 Dec 26, 2019 #2 A clunky solution would be to loop through your list & put the points into a Double array: Code: 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
A clunky solution would be to loop through your list & put the points into a Double array: Code: 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.
ThePuiu Active Member Licensed User Longtime User Dec 26, 2019 #3 Nope... Code: 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 Dec 27, 2019 #4 Code: 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
Code: 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
klaus Expert Licensed User Longtime User Dec 27, 2019 #5 @ThePuiu Sorry, but I don't understand what exactly you want to do. It seems that Erel understood. @Erel In your code you are using the same variable i in a main loop and in a second internal loop !? Upvote 0
@ThePuiu Sorry, but I don't understand what exactly you want to do. It seems that Erel understood. @Erel In your code you are using the same variable i in a main loop and in a second internal loop !?
ThePuiu Active Member Licensed User Longtime User Dec 27, 2019 #6 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 58.8 KB · Views: 530 Upvote 0
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.)
Erel B4X founder Staff member Licensed User Longtime User Dec 29, 2019 #8 ThePuiu said: The code is fully functional but unfortunately the execution time is very long (18 seconds for a set of 720 values) Click to expand... Are you testing it in release mode? It should be very fast. Upvote 0
ThePuiu said: The code is fully functional but unfortunately the execution time is very long (18 seconds for a set of 720 values) Click to expand... Are you testing it in release mode? It should be very fast.