Hi All,
seeking help on creating a pulse zig-zag chart like image below using xChart.
The data is stored in a list with maps containing level 0 or 1 (y-axis) and the duration (x-axis).
Test code snippet example using linechart but the result shows only spikes and not rectangle pulses with duration.
seeking help on creating a pulse zig-zag chart like image below using xChart.
The data is stored in a list with maps containing level 0 or 1 (y-axis) and the duration (x-axis).
Test code snippet example using linechart but the result shows only spikes and not rectangle pulses with duration.
B4X:
Private Sub DrawChart(pulses As List)
If pulses.IsInitialized = False Or pulses.Size = 0 Then Return
Log("[DrawChart] Pulses size=" & pulses.Size)
Dim time As Int = 0
Dim level As Int = 0 ' 0 = low, 1 = high
Dim duration As Int
Chart.ClearData
Chart.XMaxValue = FrameDuration
'Logic waveform line (square wave style)
Chart.AddLine("IR Logic", xui.Color_Blue)
'A pulse has 3 lines with height 1 or 0 and width duration d.
'1 +--+ +-+
' | | | |
' | | | |
'0 + +--+ +
'-> d d d
'-> time
'1 = vert-line from x-axis time to y-axis 0 or 1
'2 = hor-line from y-axis 0 or 1 to x-axis time+duration
'3 = ver-line from x-axis time+duration to y-axis 0
'time is the last position of the previous pulse
For Each pulse As Map In pulses
' Get the pulse level and duration,
level = pulse.get("level").As(Int)
duration = pulse.get("duration").As(Int)
'Log($"[DrawChart] level=${level},duration=${duration},time=${time}"$)
'1 = vert-line x-axis last time, y-axis 0 or 1
Chart.AddLinePointData(time, level, True)
'Increase the time
time = time + duration
'2 = hor-line x-axis new time, y-axis 0 or 1
Chart.AddLinePointData(time, level, True)
'3 = vert-line x-axis new time, y-axis 0
Chart.AddLinePointData(time, 0, True)
Log($"[DrawChart] level=${level},duration=${duration},time=${time}"$)
Next
Log("[DrawChart] Lines added")
Chart.DrawChart
Log("[DrawChart] DONE")
End Sub
Attachments
Last edited: