Line Plot
Use the Line Plot component to display real-time or historical data.
Real-Time Plot
To display live data from a channel or set of channels, use the Channel.LinePlot
component and provide it with a line whose variant is set to "dynamic". This will
continuously update the plot with new data as it arrives.
Example
Here’s a simple example that pulls the most recent 30 seconds of data from a channel and displays it in a line plot.
Code
Here’s the code for that example.
import { Channel, TimeSpan } from "@synnaxlabs/pluto";
const MyDynamicLinePLot = () => (
<Channel.LinePlot
style={{ width: 800, height: 500 }}
lines={[
{
key: "line1",
axes: { x: "x1", y: "y1" },
channels: {
x: "stream_write_example_time",
y: "stream_write_example_data_1",
},
color: "#3774d0",
label: "Line 1",
variant: "dynamic",
strokeWidth: 2,
timeSpan: TimeSpan.seconds(30),
},
]}
axes={[
{
key: "x1",
label: "Time",
location: "bottom",
type: "time",
},
{
key: "y1",
label: "Values",
location: "left",
},
]}
/>
);Historical Plot
You can also using the Channel.LinePlot component to display historical data. To do
this, set the variant prop of the line to "static", and provide a timeRange prop
that specifies the time range of the data to display. Here’s updated code for the
previous example that displays data from a specific time range.
const MyHistoricalLinePlot = () => (
<Channel.LinePlot
style={{ width: 800, height: 500 }}
lines={[
{
key: "line1",
axes: { x: "x1", y: "y1" },
channels: {
x: "stream_write_example_time",
y: "stream_write_example_data_1",
},
color: "#3774d0",
label: "Line 1",
variant: "static",
strokeWidth: 2,
timeRange: {
start: new Date("2022-01-01T00:00:00Z"),
end: new Date("2022-01-02T00:00:00Z"),
},
},
]}
axes={[
{
key: "x1",
label: "Time",
location: "bottom",
type: "time",
},
{
key: "y1",
label: "Values",
location: "left",
},
]}
/>
);Props
Here’s a summary of the props available for the Channel.LinePlot component.
lines
The lines prop is an array of objects that defines the lines that will be displayed on
the plot. There are two types of lines, those with variant="static" and those with
variant="dynamic". A static line is used to display historical data, and requires a
timeRange prop, while a dynamic plots rolling real-time data and requires a timeSpan
prop. Here is a summary of the props available for each type of line.
axes
The axes prop is an array of objects that define the axes to display on the plot.