Skip to content

Sparkline

A lightweight chart that draws a polyline from data points. Useful for live sensor feeds and history graphs.

lua
local history = { 21.0, 21.3, 22.1, 21.8, 23.0, 22.5, 21.9 }

ui:element({
    id = "temp_chart", type = "sparkline",
    rect = { unit = "px", x = 10, y = 50, w = 200, h = 60 },
    props = {
        data = history,
        min = 18,
        max = 28,
    },
    style = {
        bg = "#111827",
        line_color = "#22C55E",
        fill_color = "#22C55E20",  -- semi-transparent fill under line
        thickness = 2,
    }
})
PropDescription
dataArray of float values
minY-axis minimum (auto-detected if omitted)
maxY-axis maximum (auto-detected if omitted)
StyleDescription
bgBackground color
line_colorPolyline color (default green)
fill_colorArea fill under line (default transparent)
thicknessLine thickness in pixels (default 2)

Live Updating

lua
local history = { 20, 20, 20, 20, 20 }
local spark = ui:element({ id = "chart", type = "sparkline", ... })

function tick(dt)
    table.remove(history, 1)
    history[#history + 1] = ic.read(0, ic.enums.LogicType.Temperature) or 20
    spark:set_props({ data = history })
    ui:commit()
end

⚠️ This documentation was AI-generated and may contain inaccuracies. Please submit pull requests with corrections as needed.