docs/wiki/04-dynamic-and-streaming-data.md
Use ChartStreamingDataSource for live or mock dynamic feeds.
@ObservedObject private var stream = ChartStreamingDataSource(
initialValues: [18, 21, 20, 24, 23, 26],
windowSize: 6,
autoScroll: true
)
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)
stream.append(27)
stream.append(contentsOf: [26, 29, 31])
stream.reset([15, 17, 16], startingIndex: 1)
windowSize: max visible points (with autoScroll == true)autoScroll: trims oldest points after overflowxLabels: generated from current visible window indicessuggestedYRange: dynamic padded range based on current valuesTypical pattern:
[Double]stream.append(...) or stream.reset(...)ObservableObject