B4J Question [ABMaterial] ABMChart does not show the first time

Dianzoa

Active Member
Licensed User
The first time the button is clicked. I changed from Frappe Chart, because this ABMChart works better for me. But for some reason, I have to click 2 times the button to get the chart on the page. Below is the button's code. The ASPX get the correct dataset ALWAYS.
Thanks, Diego

B4X:
Sub ABMBoton_clicked( target As String)
    Dim serverurl As String
    Dim job As HttpJob

    
    ' create a bar chart
    Dim chart3 As ABMChart
    chart3.Initialize(page, "chart3", ABM.CHART_TYPEBAR, ABM.CHART_RATIO_GOLDENSECTION, "")
    ' set some options
    chart3.OptionsBar.AxisYOnlyInteger=True
    chart3.OptionsBar.ChartPaddingRight=60
        
    'FrappeChart1.Initialize(page, "FrappeChart1", "bar", "Estadistica por Hora", 250)
    DateTime.DateFormat = "YYYYMMDD"
    'fecini = ABMFecini.GetDate()
    'fecfin = ABMFecfin.GetDate()
    serverurl = "estadistica_hora.aspx"
    job.Initialize("Job1",Me)
    job.Download2(serverurl,Array As String("fecini",DateTime.Date(fecini),"fecfin",DateTime.Date(fecfin)))
    Wait For (job) jobdone(j As HttpJob)
    If j.Success Then
        Dim parser As JSONParser
        Dim response As String = job.GetString
            
        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
        page.Refresh()
    Else
        Return
    End If
    ' add the labels
    chart3.AddLabels(horas)
    ' add some series
    Dim Serie3A As ABMChartSerie
    Serie3A.InitializeForBar
    Serie3A.SetValues(valores)
    chart3.AddSerie(Serie3A)
    
    'FrappeChart1.FrappeLabels.AddAll(horas)
    'FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", valores, Array As String())

    chart3.Refresh
    page.Cell(2,1).AddComponent(chart3)
    'page.Refresh()
End Sub
 

Dianzoa

Active Member
Licensed User
Ok, this works like a charm now, I got rid of the page.refresh after jobdone, and only in this order works in any case, first the page.refresh and then the chart.refresh.
I have to add "labels" to the Y and X axis now, I will look at the methods.
B4X:
Sub ABMBoton_clicked( target As String)
    Dim serverurl As String
    Dim job As HttpJob

   
    ' create a bar chart
    Dim chart3 As ABMChart
    chart3.Initialize(page, "chart3", ABM.CHART_TYPEBAR, ABM.CHART_RATIO_GOLDENSECTION, "")
    ' set some options
    chart3.OptionsBar.AxisYOnlyInteger=True
    chart3.OptionsBar.ChartPaddingRight=60
       
    'FrappeChart1.Initialize(page, "FrappeChart1", "bar", "Estadistica por Hora", 250)
    DateTime.DateFormat = "YYYYMMDD"
    'fecini = ABMFecini.GetDate()
    'fecfin = ABMFecfin.GetDate()
    serverurl = "http://enviapy.gear.host/estadistica_hora.aspx"
    job.Initialize("Job1",Me)
    job.Download2(serverurl,Array As String("fecini",DateTime.Date(fecini),"fecfin",DateTime.Date(fecfin)))
    Wait For (job) jobdone(j As HttpJob)
    If j.Success Then
        Dim parser As JSONParser
        Dim response As String = job.GetString
           
        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
        'page.Refresh()
    Else
        Return
    End If
    ' add the labels
    chart3.AddLabels(horas)
    ' add some series
    Dim Serie3A As ABMChartSerie
    Serie3A.InitializeForBar
    Serie3A.SetValues(valores)
    chart3.AddSerie(Serie3A)
   
    'FrappeChart1.FrappeLabels.AddAll(horas)
    'FrappeChart1.AddDataSet("Cant. Pedidos", "light-blue", valores, Array As String())
    page.Cell(2,1).AddComponent(chart3)
    page.Refresh()
    chart3.Refresh
End Sub
 
Upvote 0

alwaysbusy

Expert
Licensed User
I got rid of the page.refresh after jobdone
I was wondering why that line was in there, as nothing has changed to the page at this point

I will have to investigate some more, as in my view the last chart3.refresh shouldn't be needed (the page.refresh should handle that). Moreover, instead of page.refresh, a page.cell(2,1).refresh should be enough.
 
Upvote 0

Dianzoa

Active Member
Licensed User
I was wondering why that line was in there, as nothing has changed to the page at this point

I will have to investigate some more, as in my view the last chart3.refresh shouldn't be needed (the page.refresh should handle that). Moreover, instead of page.refresh, a page.cell(2,1).refresh should be enough.

Yeap, page.cell(2,1).refresh, works instead of page.refresh, but if I take off the chart.refresh, only works for the first time, if I change the date range and click the button again, did not refresh de new dataset bars. Only works with chart.refresh.
 
Upvote 0

Dianzoa

Active Member
Licensed User
I had a little problem though, I dunno if it's a datetimepicker issue, or the chart? If I changed the year with the left arrow of the date control, to set to Dec 1 2018 and 31 dec 2018, the chart does not update. :( .
 
Upvote 0
Top