Android Tutorial [B4X] Corona Cases - Cross platform Example



Data source: https://ourworldindata.org/coronavirus-source-data

Cross platform example based on B4XTable and xChart 4.70+.
Follows the same structure as explained here: https://www.b4x.com/android/forum/threads/b4x-cross-platform-example.114125/#content
Practically all of the code is shared between the three platforms. The layouts were copied and pasted.

The project includes a default dataset in the assets folder. It tries to download an updated dataset when the app starts.

Depends on: xChart and other internal libraries.

Executable jar (Java 8 needs to be installed): https://www.b4x.com/b4j/files/CoronaCases.jar

Similar example based on xCustomListView instead of B4XTable: https://www.b4x.com/android/forum/t...loading-extension-for-xcustomlistview.115289/




Download link: www.b4x.com/android/files/CoronaCases.zip
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel.
Return this error:


The library are:

 

Xfood

Expert
Licensed User
it would be nice to add a status as default, and some labels that give you the indication of the cell date
total deaths, total infected, total recovered, new cases, new deaths
if anyone can make these changes it would be welcome,
congratulations from Erel for everything.
"EVERYTHING WILL BE FINE"
 

josejad

Expert
Licensed User
Longtime User
I get this error in B4J



Waiting for debugger to connect...
Program started.
Read countries data
Ha ocurrido un error en la línea: 297 (xChart)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.PaintOrColorToColor(B4XViewWrapper.java:886)
at b4j.example.xchart._designercreateview(xchart.java:2595)
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.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.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4j.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:62)
at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:93)
at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:84)
at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:486)
at b4j.example.sharedmain$ResumableSub_LoadData.resume(sharedmain.java:530)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
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.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.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:85)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1086)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've uploaded a new version. It depends on xChart 4.70+ which makes it simpler to change the chart size after it is created. This means that we no longer need to wait for the table to resize itself. Instead we are doing it later in DataUpdated event.

It is done with this code:
B4X:
Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
        Dim pnl As B4XView = GraphColumn.CellsLayouts.Get(i + 1) '+1 because of header layout
        Dim ChartParent As B4XView = pnl.GetView(1)
        If RowId > 0 Then
            ChartParent.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.Height)
            ChartParent.Visible = True
            Dim Chart As xChart = ChartParent.Tag
            'this is only needed in B4A as the Base_Resize event will be raised automatically in B4J and B4i.
            If xui.IsB4A Then Chart.Base_Resize(ChartParent.Width, ChartParent.Height)
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
In order to make the Yaxis scale less crowded, I added this line to the code to reduce the number of Y intervals:
B4X:
Chart.NbYIntervals=6   'I suppose it could also be done via designer
But what I really wanted to do was to be able to have the ability to hide Yvaluess from displaying on the Y Axis. For instance if my Y internal is 10, I wanted to hide every other Yvalue from displaying on the Y axis. I could not find a property for that in xChart., unless I miss it.
 

klaus

Expert
Licensed User
Longtime User
'I suppose it could also be done via designer
Sure, you can!
For instance if my Y internal is 10, I wanted to hide every other Yvalue from displaying on the Y axis. I could not find a property for that in xChart., unless I miss it.
Not yet.
 

Mahares

Expert
Licensed User
Longtime User
One very valuable feature, if it can be implemented would be to have a second Yaxis on the right for the 2nd set of data, especially in a case similar to this app, the death value is much smaller than the cases value, which in many graphs the plot for the deaths is almost flat.
 

josejad

Expert
Licensed User
Longtime User
show this errors
Post your error like text, not image.
download the missing library and copy it to your external libraries folder
 

klaus

Expert
Licensed User
Longtime User
I suppose that you have copied the xChart.xml file to the AdditionalLibraries folder.
You must remove it, only copy the xChart.b4xlib file.
You should setup the AdditionalLibraries folder like described HERE.
 

klaus

Expert
Licensed User
Longtime User
But what I really wanted to do was to be able to have the ability to hide Yvaluess from displaying on the Y Axis . . .
One very valuable feature, if it can be implemented would be to have a second Yaxis on the right for the 2nd set of data . . .
Hi Mahares,
Is this what you were expecting?



The work is still in progress, needs some fine tuning.
 

Mahares

Expert
Licensed User
Longtime User
The work is still in progress, needs some fine tuning.
That looks great klaus, It does not look like you have too far to go if you ask me. Hopefully, all the properties available now for the left Yaxis will also be available for the right Yaxis such as text color, size,, spacing intervals, etc. Are you sure you are 75 years old and not pulling our legs?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…