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

Mark Read

Well-Known Member
Licensed User
Longtime User
1. Use one time stamp for both.
This is the way I will go as it is easier and has no real effect on the chart. I only need data for the heating period now (6 months).

Ich will meine Heizung von Öl auf Luft/Wasser Wärmepumpe tauschen und brauche Vorlauftemperaturdaten! Bis 40°C Vorlauf gibts eine Förderung.

Danke für deine Hilfe.
 

emexes

Expert
Licensed User
1. Use one time stamp for both.
This is the way I will go

I'm clearly missing something here. I thought your mission was solved by the YXChart lines each having their own independent x-coordinates, plotted on the one x-axis.

Or do you absolutely definitely need those long date+time labels for the x-axis, rather than just hour or day numbers? Like, is it a format stipulated for subsidy applications?

If it is a one-off job, then maybe just use a regular spreadsheet.

If it is something you are adding to an app for other users, maybe another approach is to still go with the YX_Chart, but turn off the automatic scale labelling, and superimpose your own you-beaut labels (rotated, and with transparent backgrounds) over the top.

Anyway, I'm looking forward to seeing the end result.
 
Last edited:

Mark Read

Well-Known Member
Licensed User
Longtime User
This is what I have at present, 2 single line charts. All the data is correct (Heating chart does not have enough data yet as I only started logging this morning):

 

Mark Read

Well-Known Member
Licensed User
Longtime User
I'm clearly missing something here. I thought your mission was solved by the YXChart lines each having their own independent x-coordinates, plotted on the one x-axis.
No you are missing nothing. I tried the YXChart with the library but could not get it work as planned. I went back to the class as I know it and made two charts. This showed that I had other problems reading the data which I have now managed to solve.

I will still look at the single chart because that would look better and I would like to use the library. Watch this space!
 

klaus

Expert
Licensed User
Longtime User
I would do something like this, with one time stamp.
In the demo program you have 8000 data sets.
You can zoom 1 day, 1 week etc.
It is just a demonstrator. Up to you to adapt it to your needs.



 

Attachments

  • TemperatureMeasurement.zip
    4 KB · Views: 141

klaus

Expert
Licensed User
Longtime User
Based on my code snippet for B4XCustomFont HERE,
I suggest to modify the code as following (starting line #2271):
Can you please test the attached version of the xChart library?
I have modified the CustomFonts for B4i.

EDIT: The xChart.b4xlib file has been removed. It has been updated in the first post.
 
Last edited:

jahswant

Well-Known Member
Licensed User
Longtime User
I have this code that is running will on B4J and B4A but it hangs on B4i and sometimes this exception is raised.
I'm using the latest version of lib and B4i.
B4X:
Sub CreateBarsTab
    pnlBarCharts.ClearData
    pnlBarCharts.AddBar(Main.Loc.Localize("salesvalue"), HexToColor("#FF00BCD4"))
    pnlBarCharts.XScaleTextOrientation = "HORIZONTAL"
    pnlBarCharts.BarValueOrientation = "HORIZONTAL"
    pnlBarCharts.ChartBackgroundColor = xui.Color_White
    pnlBarCharts.GridFrameColor = xui.Color_Black
    pnlBarCharts.ValuesTextColor = xui.Color_Black
    pnlBarCharts.GridColor = xui.Color_Black
    pnlBarCharts.TitleTextColor = xui.Color_Black
    pnlBarCharts.ScaleTextColor = xui.Color_Black
    pnlBarCharts.SetBarMeanValueFormat(1, 2, 2, False)
    pnlBarCharts.Title = Main.Loc.Localize("7days")
    pnlBarCharts.XAxisName = Main.Loc.Localize("date")
    pnlBarCharts.YAxisName = Main.Loc.Localize("salesvalue")
    pnlBarCharts.SubtitleTextColor = xui.Color_Black
    pnlBarCharts.AxisTextColor = xui.Color_Black

    Wait For (POSTSELECTHTTPJOB("SQL70",Array())) JobDone(Job As HttpJob)
    If Job.Success Then
        Dim parser As JSONParser
        parser.Initialize(Job.GetString)
        Dim RootJSON As List = parser.NextArray
        For Each colroot As Map In RootJSON
            Dim Sale0 As Double = colroot.Get("Total").As(Double)
            Dim Sales_Date As String = colroot.Get("Sales_Date")
            pnlBarCharts.AddBarPointData(Sales_Date,Sale0)
        Next
    Else If Job.Success = False Then
        Toast.Show(Main.Loc.Localize("toast_an_error_occured"))
    End If
    Job.Release
    pnlBarCharts.DrawChart
End Sub

B4X:
Error occurred on line: 600 (xChart)
Object was not initialized (B4IRect)
Stack Trace: (
  CoreFoundation       __exceptionPreprocess + 242
  libobjc.A.dylib      objc_exception_throw + 48
  CoreFoundation       -[NSException initWithCoder:] + 0
  FOOD HUNTER ADMIN    -[B4IObjectWrapper object] + 111
  FOOD HUNTER ADMIN    -[B4XCanvas ClearRect:] + 34
  FOOD HUNTER ADMIN    -[b4i_xchart _xpnlcursor_touch::::] + 14444
  CoreFoundation       __invoking___ + 140
  CoreFoundation       -[NSInvocation invoke] + 305
  FOOD HUNTER ADMIN    +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
  FOOD HUNTER ADMIN    -[B4IShell runGoodChain::] + 337
 FOOD HUNTER ADMIN    -[B4IShell raiseEventImpl:method:args::] + 2536
 FOOD HUNTER ADMIN    -[B4IShellBI raiseEvent:event:params:] + 1354
 FOOD HUNTER ADMIN    -[B4IPanelView touchesCancelled:withEvent:] + 723
 UIKitCore            __106-[UIApplication _cancelViewProcessingOfTouchesOrPresses:withEvent:sendingCancelToViewsOfTouchesOrPresses:]_block_invoke + 617
 UIKitCore            -[UIApplication _cancelTouchesOrPresses:withEvent:includingGestures:notificationBlock:] + 1193
 UIKitCore            -[UIApplication _cancelViewProcessingOfTouchesOrPresses:withEvent:sendingCancelToViewsOfTouchesOrPresses:] + 152
 UIKitCore            -[UIGestureEnvironment _cancelTouches:event:] + 644
 UIKitCore            -[UIGestureRecognizer _updateGestureForActiveEvents] + 1606
 UIKitCore            _UIGestureEnvironmentUpdate + 3840
 CoreFoundation       __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
 CoreFoundation       __CFRunLoopDoObservers + 515
 CoreFoundation       __CFRunLoopRun + 1161
 CoreFoundation       CFRunLoopRunSpecific + 560
 GraphicsServices     GSEventRunModal + 139
 UIKitCore            -[UIApplication _run] + 994
 UIKitCore            UIApplicationMain + 123
 FOOD HUNTER ADMIN    main + 104
 dyld                 start_sim + 10
 ???                  0x0 + 4601546030
)
 

jahswant

Well-Known Member
Licensed User
Longtime User
There seems to be an issue here in B4i

B4X:
pnlBarCharts.AddBarPointData(Sales_Date,Sale0)
 

klaus

Expert
Licensed User
Longtime User
It is difficult to advice without seeing the entire project.
But, one point surprises me.
In the code below, if Job.Success = False you try to draw the chart !?
Are you sure that Job.Success = True in your case ?

B4X:
    Wait For (POSTSELECTHTTPJOB("SQL70",Array())) JobDone(Job As HttpJob)
    If Job.Success Then
        Dim parser As JSONParser
        parser.Initialize(Job.GetString)
        Dim RootJSON As List = parser.NextArray
        For Each colroot As Map In RootJSON
            Dim Sale0 As Double = colroot.Get("Total").As(Double)
            Dim Sales_Date As String = colroot.Get("Sales_Date")
            pnlBarCharts.AddBarPointData(Sales_Date,Sale0)
        Next
    Else If Job.Success = False Then
        Toast.Show(Main.Loc.Localize("toast_an_error_occured"))
    End If
    Job.Release
    pnlBarCharts.DrawChart
End Sub

Otherwise, could you post a small project showing the problem.
 

jahswant

Well-Known Member
Licensed User
Longtime User
I reproduced the error it seems to have something with data.

This will not work :
B4X:
For i =0  To 9
        pnlBarCharts.AddBarPointData("2022-11-1" & i,68113.49)
        'pnlBarCharts.AddBarPointData("2022-11-1" & i,Rnd(100000,500000))
    Next

But This will work :
B4X:
For i =0  To 9
        'pnlBarCharts.AddBarPointData("2022-11-1" & i,68113.49)
        pnlBarCharts.AddBarPointData("2022-11-1" & i,Rnd(100000,500000))
    Next

Wondering why.
 

Attachments

  • XChartTEST.zip
    4.2 KB · Views: 122
Cookies are required to use this site. You must accept them to continue using the site. Learn more…