B4J Question [ABMaterial] Frappe Chart does not show

Dianzoa

Active Member
Licensed User
Am I missing something? Below I post the relevant snippet code

B4X:
public Sub BuildPage()
    ' initialize the theme
    BuildTheme
    
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "estadistica.html"
    page.PageTitle = "Estadistica"
    page.PageDescription = "Estadistica"
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
        
    page.ShowConnectedIndicator = True
                
    ' adding a navigation bar
    
    ABMShared.BuildNavigationBar(page, "EnviaPy - Estadisticas","../images/logo.png", "", "", "")   
    theme.AddCellTheme("centercontent")
    theme.Cell("centercontent").Align = ABM.CELL_ALIGN_CENTER
    ' create the page grid
    page.AddRow(1,True,"","")
    page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
    page.AddExtraJavaScriptFile("custom/frappe-charts.min.iife.425.js")
    
End Sub

B4X:
public Sub ConnectPage()           
    '    connecting the navigation bar
    ABMShared.ConnectNavigationBar(page)
    FrappeChart1.Initialize(page, "FrappeChart1", "bar", "Estadistica por Hora", 250)
    'llamar al job al SQL que trae las cantidades
    Dim job As HttpJob
    Dim serverurl As String
    Dim fecini,fecfin As String
    fecini = "20190101"
    fecfin = "20190131"
    serverurl = "database_retrieval.aspx"
    job.Initialize("Job1",Me)
    job.Download2(serverurl,Array As String("fecini",fecini,"fecfin",fecfin))
    ' refresh the page
'    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition   

End Sub

And in jobdone I want to populate the values for the bar chart.

B4X:
Sub jobdone (Job As HttpJob)
    'page.Msgbox("","Entro","Error","Aceptar",False,"","")
    If Job.Success Then
        If Job.JobName = "Job1" Then
            Dim parser As JSONParser
            Dim response As String = Job.GetString
            Dim valores As List
            Dim valor As Int
            valores.Initialize()
            'Msgbox("entro","")
            parser.Initialize(response)
            Dim rows As List
            rows = parser.NextArray
            If rows.Size = 0 Then
                'page.Msgbox("contraseña_i","Error de Usuario y/o Contraseña","Error","Aceptar",False,"","")
                'Return
            End If
            'work with result
            'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
            
            FrappeChart1.FrappeLabels.AddAll(Array As String("7", "8", "9", "10","11", "12", "13", "14","15","16","17","18","19","20","21","22","23","24"))
            For i = 0 To rows.Size - 1
                
                'Log("Rows #" & i)
                Dim m As Map
                m = rows.Get(i)
'                Msgbox(i,"")
                'Msgbox(m.Get("idrepartidor"),"")
                'page.Msgbox("contraseña_i",m.Get("idcliente"),"Error","Aceptar",False,"","")
                valor = m.Get("cantidad")
                valores.Add(valor)
                DateTime.DateFormat = "dd/MM/yyyy hh:mm"
                
                'FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", Array As Int(25, 40, 30, 35, 8, 52, 17, -4), Array As String())
    
                
            Next
            FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", valores, Array As String())
        End If
        

    End If
    Job.Release
    page.Cell(1,1).AddComponent(FrappeChart1.ABMComp)
    'Main.cerrado = False
    page.Refresh   
    
End Sub

And there are a couple of warnings
Waiting for value (100 ms)
Unexpected event (missing RaiseSynchronousEvents): abmcomp_build
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1336)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:199)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor1.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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at com.ab.abmaterial.ABMCustomComponent.Build(Unknown Source)
at com.ab.abmaterial.ABMCell.RefreshInternalExtra(Unknown Source)
at com.ab.abmaterial.ABMRow.RefreshInternal(Unknown Source)
at com.ab.abmaterial.ABMPage.Refresh(Unknown Source)
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.runVoidMethod(Shell.java:672)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor1.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:90)

and...

Unexpected event (missing RaiseSynchronousEvents): abmcomp_firstrun
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1336)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:199)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor1.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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at com.ab.abmaterial.ABMCustomComponent.FirstRun(Unknown Source)
at com.ab.abmaterial.ABMComponent.RunAllFirstRuns(Unknown Source)
at com.ab.abmaterial.ABMCell.RefreshInternalExtra(Unknown Source)
at com.ab.abmaterial.ABMRow.RefreshInternal(Unknown Source)
at com.ab.abmaterial.ABMPage.Refresh(Unknown Source)
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.runVoidMethod(Shell.java:672)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor1.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:90)


Any tips?
Thanks, Diego
 

Dianzoa

Active Member
Licensed User
Does this happen when pressing F5 or at first run too? (F5 has an issue with custom components for which I have not found a solution yet)

Do you see errors in the browser console or network tab? (Chrome, F12)
Strange, I just change tabs, and then back to the tab where the app si running and it shows the bars!. If I don't do this, it appears "null" in the page.
BTW, I use Opera browser.
 
Upvote 0

Dianzoa

Active Member
Licensed User
Just another thing. When in debug mode, if you make a change to the B4J code while running and press save, you will get this error.
Now I try to do variable charts, changing the initial date and final date, but the chart does not show , only works with the first date variables. I have to delete the dataset before assigning new datasets?
Only works the first time. When I changed the date range not longer update the bars.

B4X:
Sub jobdone (Job As HttpJob)
    'page.Msgbox("","Entro","Error","Aceptar",False,"","")
    If Job.Success Then
        If Job.JobName = "Job1" Then
            Dim parser As JSONParser
            Dim response As String = Job.GetString
            Dim valores As List
            Dim valor As Int
            Dim horas As List
            valores.Initialize()
            horas.Initialize
            horas.Clear
            valores.Clear
            'Msgbox("entro","")
            parser.Initialize(response)
            Dim rows As List
            rows = parser.NextArray
            If rows.Size = 0 Then
                'page.Msgbox("contraseña_i","Error de Usuario y/o Contraseña","Error","Aceptar",False,"","")
                'Return
            End If
            'work with result
            'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
          
          
            For i = 0 To rows.Size - 1
              
                'Log("Rows #" & i)
                Dim m As Map
                m = rows.Get(i)
'                Msgbox(i,"")
                'Msgbox(m.Get("idrepartidor"),"")
                'page.Msgbox("contraseña_i",m.Get("idcliente"),"Error","Aceptar",False,"","")
                valor = m.Get("cantidad")
                valores.Add(valor)
                hora = m.Get("HoraPedido")
                horas.Add(hora)
                'FrappeChart1.FrappeLabels.Add(hora)
                'FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", Array As Int(25, 40, 30, 35, 8, 52, 17, -4), Array As String()) 
            Next
            'FrappeChart1.FrappeLabels.AddAll(Array As String("7", "8", "9", "10","11", "12", "13", "14","15","16","17","18","19","20","21","22","23","24"))
            FrappeChart1.FrappeLabels.AddAll(horas)
            FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", valores, Array As String())
        End If
      
    End If
    Job.Release
    page.Cell(2,1).AddComponent(FrappeChart1.ABMComp)
    'Main.cerrado = False
    page.Refresh 
 
End Sub

Sub ABMFecini_Changed(Target As String, dateMilliseconds As String)
    ' convert To a B4J date
    fecini = dateMilliseconds
End Sub
Sub ABMFecfin_Changed(Target As String, dateMilliseconds As String)
    ' convert To a B4J date
    fecfin = dateMilliseconds
End Sub

Sub ABMBoton_clicked( target As String)
    Dim serverurl As String
    Dim job As HttpJob
    DateTime.DateFormat = "YYYYMMDD"
    serverurl = "estadistica_hora.aspx"
    job.Initialize("Job1",Me)
    job.Download2(serverurl,Array As String("fecini",DateTime.Date(fecini),"fecfin",DateTime.Date(fecfin)))
End Sub
 
Last edited:
Upvote 0
Top