B4J Library [B4X] [XUI] xChart Class and b4xlib

swChef

Member
Licensed User
Thank you, I will add it.
The code above is enough.
Hi klaus,

Did you decide not to include this?

B4X:
Public Sub ClearPointsFrom(LineIndex As Int)
    Private ID As ItemData
    If Graph.ChartType = "YX_CHART" And Items.Size > LineIndex Then
            ID = Items.Get(LineIndex)
            ID.YXArray.Initialize
    End If
End Sub
 

swChef

Member
Licensed User
klaus,

I swapped the 7.2beta in for my copy, and pushed over the ClearPointsFrom change.

I get an exception at 3429 on the RemoveClip in DrawPoint (last statement in the Case "TRIANGLE"; should match yours, my insertion was at 5378).
I swapped back to my modified 7.0, no problem.
Went back to the 7.2beta with my insertion, and commented out that line, and now my app runs as it did with 7.0
I checked and that removeclip is new since 7.0, and there is also a new one at Case "RHOMBUS" at the end.
No other uses of removeclip changed.
My app does use the TRIANGLE shape.

Let me know if you need a copy of my app, it is just a testapp to try out several things related to geo positioning and xchart.

Here's the relevant log content:

B4X:
xchart_drawpoint (java line: 6249)
java.lang.IllegalStateException: Underflow in restore - more restores than saves
    at android.graphics.Canvas.restore(Canvas.java:586)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper.RemoveClip(CanvasWrapper.java:485)
    at anywheresoftware.b4a.objects.B4XCanvas.RemoveClip(B4XCanvas.java:95)
    at b4a.geofence.xchart._drawpoint(xchart.java:6249)
    at b4a.geofence.xchart._drawyxlines(xchart.java:7804)
    at b4a.geofence.xchart._drawchart(xchart.java:4698)
    at b4a.geofence.main._location_changed(main.java:1023)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
    at b4a.geofence.flpservice._flp_locationchanged(flpservice.java:377)
    at b4a.geofence.flpservice._flp_connectionsuccess(flpservice.java:367)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProvider.onConnected(FusedLocationProvider.java:64)
    at com.google.android.gms.common.internal.zah.zaa(com.google.android.gms:play-services-base@@17.4.0:30)
    at com.google.android.gms.common.api.internal.zaap.zaa(com.google.android.gms:play-services-base@@17.4.0:295)
    at com.google.android.gms.common.api.internal.zaad.zaf(com.google.android.gms:play-services-base@@17.4.0:130)
    at com.google.android.gms.common.api.internal.zaad.zaa(com.google.android.gms:play-services-base@@17.4.0:108)
    at com.google.android.gms.common.api.internal.zaax.onConnected(com.google.android.gms:play-services-base@@17.4.0:105)
    at com.google.android.gms.common.api.internal.zap.onConnected(com.google.android.gms:play-services-base@@17.4.0:5)
    at com.google.android.gms.common.internal.zag.onConnected(com.google.android.gms:play-services-base@@17.4.0:2)
    at com.google.android.gms.common.internal.BaseGmsClient$zzf.zza(com.google.android.gms:play-services-basement@@17.4.0:24)
    at com.google.android.gms.common.internal.BaseGmsClient$zza.zza(com.google.android.gms:play-services-basement@@17.4.0:12)
    at com.google.android.gms.common.internal.BaseGmsClient$zzc.zzc(com.google.android.gms:play-services-basement@@17.4.0:11)
    at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(com.google.android.gms:play-services-basement@@17.4.0:49)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6710)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
*#*#*#* crash
App crashed java.lang.IllegalStateException: Underflow in restore - more restores than saves
    at android.graphics.Canvas.restore(Canvas.java:586)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper.RemoveClip(CanvasWrapper.java:485)
    at anywheresoftware.b4a.objects.B4XCanvas.RemoveClip(B4XCanvas.java:95)
    at b4a.geofence.xchart._drawpoint(xchart.java:6249)
    at b4a.geofence.xchart._drawyxlines(xchart.java:7804)
    at b4a.geofence.xchart._drawchart(xchart.java:4698)
    at b4a.geofence.main._location_changed(main.java:1023)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1037)
    at b4a.geofence.flpservice._flp_locationchanged(flpservice.java:377)
    at b4a.geofence.flpservice._flp_connectionsuccess(flpservice.java:367)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProvider.onConnected(FusedLocationProvider.java:64)
    at com.google.android.gms.common.internal.zah.zaa(com.google.android.gms:play-services-base@@17.4.0:30)
    at com.google.android.gms.common.api.internal.zaap.zaa(com.google.android.gms:play-services-base@@17.4.0:295)
    at com.google.android.gms.common.api.internal.zaad.zaf(com.google.android.gms:play-services-base@@17.4.0:130)
    at com.google.android.gms.common.api.internal.zaad.zaa(com.google.android.gms:play-services-base@@17.4.0:108)
    at com.google.android.gms.common.api.internal.zaax.onConnected(com.google.android.gms:play-services-base@@17.4.0:105)
    at com.google.android.gms.common.api.internal.zap.onConnected(com.google.android.gms:play-services-base@@17.4.0:5)
    at com.google.android.gms.common.internal.zag.onConnected(com.google.android.gms:play-services-base@@17.4.0:2)
    at com.google.android.gms.common.internal.BaseGmsClient$zzf.zza(com.google.android.gms:play-services-basement@@17.4.0:24)
    at com.google.android.gms.common.internal.BaseGmsClient$zza.zza(com.google.android.gms:play-services-basement@@17.4.0:12)
    at com.google.android.gms.common.internal.BaseGmsClient$zzc.zzc(com.google.android.gms:play-services-basement@@17.4.0:11)
    at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(com.google.android.gms:play-services-basement@@17.4.0:49)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6710)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
 

klaus

Expert
Licensed User
Hi klaus,

Did you decide not to include this?

B4X:
Public Sub ClearPointsFrom(LineIndex As Int)
Private ID As ItemData
If Graph.ChartType = "YX_CHART" And Items.Size > LineIndex Then
ID = Items.Get(LineIndex)
ID.YXArray.Initialize
End If
End Sub
Yes, I decided to not include it because I find it too specific.
Sorry for not having reported it.
You can do it easily in your code:
B4X:
Private ID As ItemData
ID = YX_Chart1.Items.Get(LineIndex)
ID.YXArray.Clear
I get an exception at 3429 on the RemoveClip in DrawPoint
Thank you for reporting this.
This RemoveClip must be removed. I had added them for tests and forgot to remove them.
Done for the next update.
 

Laurent95

Active Member
Licensed User
Thank you Peter for testing.
I had also seen the problem in the mean time with the second click.
It has already been amended for the 'official' update.
Hi all,

@klaus
I don't know if it's the same problem but if i take a lot of data and put the chart zoomed. And that the next time i take less data and no need to zoom i got an error on line 2389 of class too. I mean without close the application, if i close between, no error.
Log below:
B4X:
Waiting for debugger to connect...
Program started.
.../... A lot of log
Here 5 years choosen in settings

cbChartDuration_SelectedIndexChanged- Index: 9 Value: Valeurs depuis 5 ans
Nouvelle valeur ChartDuration: Last5Years
KVStore ChartDuration: Last5Years
Date start: 29/03/2016
datelongStart: 1459202400000
Date Stop: 29/03/2021
datelongStopt: 1616968800000
requête SQL: SELECT Date, Rate, DateLong FROM Currencies WHERE Currency='PHP' AND DateLong >=1459202400000 AND DateLong <=1616968800000 ORDER BY DateLong ASC
ExecuteMemoryTable: SELECT Date, Rate, DateLong FROM Currencies WHERE Currency='PHP' AND DateLong >=1459202400000 AND DateLong <=1616968800000 ORDER BY DateLong ASC
Minimum rate: 51.65
Maximum rate: 65.14
KVStore ChartColor: Magenta
Color: -65281
Ok show the chart

Here i choose 1 year in settings, so by code no zoom
cbChartDuration_SelectedIndexChanged- Index: 5 Value: Valeurs depuis 1 an
Nouvelle valeur ChartDuration: Last1Year
KVStore ChartDuration: Last1Year
Date start: 29/03/2020
datelongStart: 1585436400000
Date Stop: 29/03/2021
datelongStopt: 1616968800000
requête SQL: SELECT Date, Rate, DateLong FROM Currencies WHERE Currency='PHP' AND DateLong >=1585436400000 AND DateLong <=1616968800000 ORDER BY DateLong ASC
ExecuteMemoryTable: SELECT Date, Rate, DateLong FROM Currencies WHERE Currency='PHP' AND DateLong >=1585436400000 AND DateLong <=1616968800000 ORDER BY DateLong ASC
Minimum rate: 54.39
Maximum rate: 59.49
KVStore ChartColor: Magenta
Color: -65281
crash when chart is showed:
Une erreur s'est produite en ligne : 2389 (xChart)
Seems the points of zoom stay and are not good
java.lang.IndexOutOfBoundsException: Index: 24, Size: 13
    at java.util.ArrayList.rangeCheck(ArrayList.java:659)
    at java.util.ArrayList.get(ArrayList.java:435)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:105)
    at b4j.MoneyConverter.xchart._getbarpointsminmaxvalues(xchart.java:2764)
    at b4j.MoneyConverter.xchart._calcscalemanu(xchart.java:3259)
    at b4j.MoneyConverter.xchart._initchartv(xchart.java:14540)
    at b4j.MoneyConverter.xchart._initchart(xchart.java:7928)
    at b4j.MoneyConverter.xchart._drawchart(xchart.java:1073)
    at b4j.MoneyConverter.main._vbarchart(main.java:7080)
    at b4j.MoneyConverter.main$ResumableSub_sysIcon_MenuClick.resume(main.java:5570)
    at b4j.MoneyConverter.main._sysicon_menuclick(main.java:5025)
    at b4j.MoneyConverter.main._lblcurnametarget_mouseclicked(main.java:5626)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:110)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
    at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:941)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
    at java.lang.Thread.run(Thread.java:748)
I fixed that in my code with use not only xChart.ClearData but with add also xChart.ClearPoints. And in case i don't need zoomed charts, i put a xChart.unzoom command in more. Now it's ok, no more error.
I need to test a bit more to see if the 3 commands are needed or not

I saw something, even on demo program. Maybe it's possible to correct it.
With window who have a zoomed xChart, if you change the size, the scroll bar stay at initial width of the window, screenshot below :
Initial size
scrollbar_Initial size of window-its ok.png
scrollbar_not follow the size of window.png
Resized
It's possible to use it, it's only an aesthétic aspect :)

Something other but i need more time to search about, i haven't any error in log, just a gray xChart with "Error, no data". I get that even when i search 6 months of exchange rates. It's weird because i have more than 10 years of historic in database and in log i have the Minrate and Maxrate printed, so i'm quite sure i have data ? I will put break points an see why. It's maybe in my code.

I'll not be at home this afternoon, so i'll test more tonight or tomorrow.

Have a nice day,
Laurent
 

klaus

Expert
Licensed User
Hi Laurent.
Thank you for your testings.
I don't know if it's the same problem but if i take a lot of data and put the chart zoomed. And that the next time i take less data and no need to zoom i got an error on line 2389 of class too. I mean without close the application, if i close between, no error.
Now it's ok, no more error.
I need to test a bit more to see if the 3 commands are needed or not
In the mean time I have seen this too, it is amended.
Therefore no need to investigate further for this.

With window who have a zoomed xChart, if you change the size, the scroll bar stay at initial width of the window, screenshot below :
I am currently working on this.

The update is still in work, there are still some other problems.
Before testing further, please wait for the next beta update.
 

madru

Active Member
Licensed User
Hi Klaus,

can you please verify that #392 is really fixed, looks like that the top is still drawing into the boarder , right side looks OK

1617473059814.png
 

klaus

Expert
Licensed User
The xChart class and library has been update to version 7.2 in the first post.
NEW
New chart type: H_LINE, horizontal line
This chart type is a LINE chart but with the X and Y axes swapped. The values scale is horizontal instead of vertical.
It is similar to the H_BAR and H_STACKED_BAR charts.
Zoom, charts can be zoomed with the SetZoomIndexes(BeginIndex As Int, EndIndex As Int) method.

Notes:
The SubitleTextColor property has been set to SubtitleTextColor
The HBarsXScaleOnTop property has been set to HChartsXScaleOnTop
The HBarsTicksTopDown property has been set to HChartsTicksTopDown

Added H_LINE, horizontal line chart type
Changed the HBarsXScaleOnTop property to HChartsXScaleOnTop
Changed the HBarsTicksTopDown property to HChartsTicksTopDown
Added ReverseYScale property
Added SetZoomIndexes(BeginIndex As Int, EndIndex As Int) method
Added UnZoom method
Added JumpTo(Index As InT) method, jumps to a giev undex when the chart is zoomed
Added ScalesOnZoomedPart properts
Version 7.1
Changed SubitleTextColor property typo to SubtitleTextColor
Amended display legend position
Improved legend display position for Radar charts
Added ReverseYScale property for YXCharts
 

Laurent95

Active Member
Licensed User
Hi all

@klaus
Thank you for the update :cool:

Have a nice day
 
Top