You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For posterity (three years later), as a workaround you can inject the <defs> tag after the sparkline has been created.
For example:
sparkline(svgEl,props.data,options)// Inject the gradientconstsvgNS="http://www.w3.org/2000/svg"constdefs=document.createElementNS(svgNS,"defs")constlinearGradient=document.createElementNS(svgNS,"linearGradient")linearGradient.setAttribute("id","verticalGradient")// Make the gradient verticallinearGradient.setAttribute("x1","0%")linearGradient.setAttribute("y1","0%")linearGradient.setAttribute("x2","0%")linearGradient.setAttribute("y2","100%")conststop1=document.createElementNS(svgNS,"stop")stop1.setAttribute("offset","0%")stop1.setAttribute("stop-color","var(--color-stop)")conststop2=document.createElementNS(svgNS,"stop")stop2.setAttribute("offset","30%")stop2.setAttribute("stop-color","var(--color-stop)")conststop3=document.createElementNS(svgNS,"stop")stop3.setAttribute("offset","95%")stop3.setAttribute("stop-color","var(--color-bot)")linearGradient.appendChild(stop1)linearGradient.appendChild(stop2)linearGradient.appendChild(stop3)defs.appendChild(linearGradient)svgEl.appendChild(defs)
Hi 👋,
First of all thank you very much for this awesome library, I like it a lot!
But I got a question: I'd like to fill the backrgound of my sparkline with a gradient, like so:
But this throws the following error, because sparkline tries to remove all children of the element first.
Do you have any idea how to prevent this error?
Thanks,
Christian
The text was updated successfully, but these errors were encountered: