Real-time scrolling data¶
Keep the viewport fixed and replace the visible buffer once per frame.
Declare a stable viewport¶
import QtQuick
import QAccelPlot as QAccelPlot
QAccelPlot.Plot {
id: plot
xAxis: QAccelPlot.Axis {
viewportMin: -20
viewportMax: 0
label: "Time before present (s)"
}
yAxis: QAccelPlot.Axis {
viewportMin: -2.5
viewportMax: 2.5
label: "Acceleration (g)"
}
QAccelPlot.LineCurve {
objectName: "vibrationCurve"
xAxis: plot.xAxis
yAxis: plot.yAxis
lineWidth: 2.5
}
}
Update every frame¶
Pass each new buffer to setDataF():
A rescale fits the data points of the current frame. To fit the nominal window instead, pass its bounds with the data. This also skips the range scan:
constexpr auto bounds = QAccelPlot::PlotSeries::DataBounds{-20.0, 0.0, -2.5, 2.5};
curve->setDataF(std::move(points), pointCount, bounds);
If buffer generation is expensive, move it to a worker thread; see Background data production.
Follow the data range¶
To fit an axis to the data instead of fixing its viewport, set
autoRescale. The viewport is refitted on every data update,
including each appendData() call:
- The fit is exact, as with
rescaleToData(). - A panned or zoomed viewport is replaced on the next update. Set
autoRescaletofalsewhile the user navigates. - Appending only extends the data range. Replace the buffer with
setDataF()to let the range shrink. - Each update scans the data for its range, unless it appends or passes bounds.
- When the last series on the axis is cleared, the viewport is kept.
Show dropouts as gaps¶
Write NaN for lost or invalid data points instead of repeating or dropping them.
The curve breaks there, and the gap is excluded from auto-ranging and hover:
const auto value = packet.valid ? packet.value : std::numeric_limits<float>::quiet_NaN();
points[index * 2] = timestamp;
points[index * 2 + 1] = value;
To draw across dropouts instead, set
gaps.nanMode: QAccelPlot.NanGapMode.Connect. See
Invalid data points and gaps.
Complete sources: