Graph
A single chart bound to a container frame. Renders line and bar series with animated entries, gradient infill, optional smoothing, hover tooltips, and a legend, and re-renders automatically when the data, configuration, or container size changes. Renders are deferred and coalesced, so several mutations in one frame produce a single redraw.
Create one with Plottr.new.
Functions
new
Creates a new graph that renders into the given container. The graph fills the container and starts empty; add data with Graph:setSeries.
setSeries
Replaces all series and re-renders with the entry animation. The series and their value arrays are copied, so the graph never mutates what you pass in.
Errors
| Type | Description |
|---|---|
| duplicate series name | Thrown when two series share a name |
addSeries
Appends one series and re-renders with the entry animation.
Errors
| Type | Description |
|---|---|
| duplicate series name | Thrown when a series with that name exists |
removeSeries
Graph:removeSeries(name: string) → boolean--
Whether a series with that name existed
Removes the series with the given name.
updateSeries
Graph:updateSeries(name: string,values: {number}) → boolean--
Whether a series with that name existed
Replaces the values of one series and redraws instantly, without replaying the entry animation.
getSeries
Returns a copy of the named series, or nil when there is no such series. The copy is detached: mutating it does not affect the graph.
getSeriesNames
Graph:getSeriesNames() → {string}Returns every series name, in render order.
setSeriesVisible
Graph:setSeriesVisible(name: string,visible: boolean) → boolean--
Whether a series with that name existed
Shows or hides one series without removing its data. Hidden series are left out of the axis range and dimmed in the legend.
clear
Graph:clear() → ()Removes every series, leaving an empty plot.
push
Graph:push(seriesName: string,value: number) → ()Appends a value to the named series and redraws instantly, without replaying the entry animation — intended for realtime/streaming data. When Config.maxPoints is set, older values scroll off the front. Multiple pushes in one frame coalesce into a single redraw.
Errors
| Type | Description |
|---|---|
| unknown series | Thrown when no series has the given name |
configure
Graph:configure(config: PartialConfig) → ()Merges the given options into the current configuration and re-renders. Set an optional field to Plottr.None to clear it back to nil.
setTheme
Swaps the theme and re-renders.
onPointClicked
Registers a handler for clicks on a data point or bar. Returns a function that unregisters it.
local disconnect = graph:onPointClicked(function(event)
print(event.seriesName, event.index, event.value)
end)
render
Graph:render() → ()Forces an immediate animated re-render, cancelling any redraw that was already queued for this frame.
destroy
Graph:destroy() → ()Destroys the graph and every instance it created. Safe to call twice.