To be honest, I don't see how there could be another way, logically... An SVG line can only have one color, just as a circle or a square can only have one color
Y
ou could in theory use some clever CSS gradient trick, but it's nearly impossible to set the threshold at the exact desired coordinate...