Skip to content

Line Chart

LineChart draws one field of its events against another.

import dachshund
from dachshund.widgets import LineChart

with dachshund.row():
    dachshund.add(LineChart("throughput", x="requests", y="latency"))
dachshund.emit("throughput", requests=120, latency=96)

dachshund.widgets.chart.line.LineChart dataclass

LineChart(name, *, source='', title=None, actions=list(), action_args=dict(), x, y='value')

Bases: Widget

A line of one field against another.

An event without x isn't drawn. To draw against when events happened, see TimeSeriesChart.

Example

with dachshund.row():
    dachshund.add(LineChart("throughput", x="requests", y="latency"))
dachshund.emit("throughput", requests=120, latency=96)

Options

  • x (str) - The field placing a point. Required.
  • y (str | list[str]) - The field drawn, or one line per field. Defaults to "value".

x instance-attribute

x

y class-attribute instance-attribute

y = 'value'

type class-attribute

type = 'line'

op class-attribute

op = 'append'

script class-attribute

script = Path(__file__).parent / 'charts.js'

style class-attribute

style = Path(__file__).parent / 'charts.css'

rollup_safe class-attribute

rollup_safe = True

series property

series

The fields this chart draws, a line each.

render

render(events)

Build the columns uPlot draws its series from.

Source code in dachshund/widgets/chart/line.py
57
58
59
60
61
62
63
64
65
66
67
def render(self, events: Sequence[Event]) -> dict[str, Any]:
    """Build the columns uPlot draws its series from."""
    rows = [row for row in map(self.update, events) if row is not None]

    return {
        "series": list(self.series),
        "x": [row["x"] for row in rows],
        "y": [
            [row["y"][index] for row in rows] for index in range(len(self.series))
        ],
    }

update

update(event)

Build the row a new event appends, a value per series.

Returns None when the event has no readable x to place it at.

Source code in dachshund/widgets/chart/line.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def update(self, event: Event) -> dict[str, Any] | None:
    """Build the row a new event appends, a value per series.

    Returns `None` when the event has no readable x to place it at.
    """
    at = self.at(event)

    if at is None:
        self.warn(self.x, event.payload.get(self.x))
        return None

    return {
        "x": at,
        "y": [self.value(event, field) for field in self.series],
    }

at

at(event)

Where along the x axis the event's own reading puts it.

Returns None when the event carries no usable reading.

Source code in dachshund/widgets/chart/line.py
85
86
87
88
89
90
def at(self, event: Event) -> float | None:
    """Where along the x axis the event's own reading puts it.

    Returns `None` when the event carries no usable reading.
    """
    return numeric(event.payload.get(self.x))