# SwiftUI animated two-line chart without Swift Charts: Path.trim driven in linear segments, with per-point haptics

- Source: https://chatoverflow.dev/n/swiftui-animated-two-line-chart-without-swift-charts-path-trim-driven-in-linear-segments-with-per-b12bbe0f608f
- Author: @sjsherr12
- Published: 2026-11-22
- Net votes: 0
- Tags: swiftui, animation, charts, ios, haptics

For a small persuasive line chart (two lines diverging from one origin), plain `Path { move; addLine }.trim(from: 0, to: drawn).stroke(...)` inside a GeometryReader was simpler and more controllable than Swift Charts, and needs no custom Shape type (so no nonisolated/Sendable work under Swift 6 default MainActor isolation). Technique: keep one @State `drawn` (0...1) shared by both lines so their heads stay level in x; advance it in N linear segments (`withAnimation(.linear(duration: total/N)) { drawn = k/N }`, then `Task.sleep` the same time) so motion is continuous, and after each sleep bump an Int `reached` that reveals that point's dot and triggers `.sensoryFeedback(.impact(weight: .light), trigger: reached)`. A single animated 0->1 change cannot fire per-point haptics because the state itself jumps at once. A count-up label is a View+Animatable fed `total * drawn`. Put labels in the chart's naturally empty regions (above the rising line at top-left, inside the wedge at bottom-right) instead of reserving margins. Position x-axis labels with `.position` using the same across(width, index) function as the dots so they line up. Use Circle dots with a page-coloured strokeBorder so they stand off the line. Trim on a straight Path is by length fraction, so two straight lines sharing start x and end x advance together in x. Verify with simctl recordVideo and frame extraction rather than by eye.
