Hi, i have this code that takes data from an API call and should publish them in xChartLite object, but compiler is telling me : "Unknown member: initialize".
I don't find any initialize command inside . Which is the real reason ?
Thank you in advance
I don't find any initialize command inside . Which is the real reason ?
Thank you in advance
B4X:
' -------------------
' MainPage - xChartLite Version
' -------------------
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Chart As xChartLite
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
' Inizializzazione OBBLIGATORIA per xChartLite
CaricaGrafico
End Sub
' ================== HTTP - OKHttpUtils2 ==================
Sub CaricaGrafico
Dim url As String = "http://194.243.139.130:5000/api/velo?apikey=KoenigBauer2026!&idmacchina=1&fixdata=260325"
Dim Job As HttpJob
Job.Initialize("VeloJob", Me)
Job.Download(url)
End Sub
Sub JobDone (Job As HttpJob)
If Job.Success = False Then
Log("Errore connessione: " & Job.ErrorMessage)
ToastMessageShow("Errore connessione API", True)
Job.Release
Return
End If
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim RootMap As Map
Dim data As List
Try
RootMap = parser.NextObject
data = RootMap.Get("data")
Catch
Log("Errore parsing JSON")
ToastMessageShow("Errore nel JSON ricevuto", True)
Job.Release
Return
End Try
If data.IsInitialized = False Or data.Size = 0 Then
ToastMessageShow("Nessun dato disponibile", True)
Job.Release
Return
End If
' Prepara dati per il grafico
Dim yVel(data.Size) As Double
Dim ySP(data.Size) As Double
Dim xLabels As List : xLabels.Initialize
DateTime.DateFormat = "dd/MM/yyyy HH:mm:ss"
Dim i As Int = 0
For Each m As Map In data
Try
Dim datas As String = m.Get("DataRun")
Dim velocita As Double = m.Get("velocita")
Dim sp As Double = m.Get("velocitaSP")
Dim t As Long = DateTime.DateParse(datas)
Dim label As String = DateTime.Time(t).SubString2(0, 5) ' hh:mm
xLabels.Add(label)
yVel(i) = velocita
ySP(i) = sp
i = i + 1
Catch
Log("Dati non validi saltati: " & m)
End Try
Next
DisegnaGrafico(xLabels, yVel, ySP)
Job.Release
End Sub
' ================== DISEGNA GRAFICO con xChartLite ==================
Sub DisegnaGrafico(xLabels As List, yVel() As Double, ySP() As Double)
If Chart.IsInitialized = False Then
Log("xChartLite non inizializzato")
Return
End If
Chart.ClearData
' Impostazioni generali
Chart.ChartType = "LINE"
Chart.DrawXScale = True
Chart.DrawYScale = True
Chart.DrawGridFrame = True
Chart.AxisTextColor = xui.Color_Black
Chart.Title = "Velocità Macchina"
Chart.TitleTextColor = xui.Color_Black
' Aggiunge le due linee
Chart.AddLine("Velocità", xui.Color_Blue)
Chart.AddLine("Setpoint", xui.Color_Red)
' Aggiunge i punti (una chiamata per ogni X)
For i = 0 To xLabels.Size - 1
Dim label As String = xLabels.Get(i)
Chart.AddLinePointData(label, yVel(i), True) ' True = mostra etichetta X
Chart.AddLinePointData(label, ySP(i), True)
Next
Chart.DrawChart
End Sub