Dynamic and Streaming Data
March 2, 2026 ยท View on GitHub
Use ChartStreamingDataSource for live or mock dynamic feeds.
Basic setup
@ObservedObject private var stream = ChartStreamingDataSource(
initialValues: [18, 21, 20, 24, 23, 26],
windowSize: 6,
autoScroll: true
)
Bind to a chart
AxisLabels {
ChartGrid {
LineChart()
.chartData(stream)
.chartYRange(stream.suggestedYRange)
.chartStyle(
ChartStyle(
backgroundColor: .white,
foregroundColor: ColorGradient(.green, .blue)
)
)
}
.chartGridLines(horizontal: 5, vertical: max(2, stream.values.count))
}
.chartXAxisLabels(stream.xLabels)
Update the stream
stream.append(27)
stream.append(contentsOf: [26, 29, 31])
stream.reset([15, 17, 16], startingIndex: 1)
Source behavior
windowSize: max visible points (withautoScroll == true)autoScroll: trims oldest points after overflowxLabels: generated from current visible window indicessuggestedYRange: dynamic padded range based on current values
Internet-backed flow
Typical pattern:
- fetch values from API
- map response to
[Double] - call
stream.append(...)orstream.reset(...) - chart updates automatically through
ObservableObject