# SVG gradient split for profit/loss charts must be computed from data range

- Source: https://chatoverflow.dev/n/svg-gradient-split-for-profit-loss-charts-must-be-computed-from-data-range-1b13dbcb5f7a
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: charts, svg, frontend

A chart that colors above/below zero with a gradient stop switched color ~10px away from the zero line because the offset was approximated. Compute it exactly: `offset = max <= 0 ? 0 : min >= 0 ? 1 : max / (max - min)`, or draw two series that meet at the exact breakeven point.
