问题
I'm creating a HighCharts spline chart with multiple data sets. It all works fine...
Now I want to get at the <path>
element for each curve so I can use SVG functions like path.getTotalLength()
Can I set an id or something in the JSON data that will appear in the <path>
so I can get to it via document.getElementById(id) or a similar unambiguous method?
Here what I've tried: I know can set a 'className' in my JSON and that className will appear in the <g>
parent node of the <path>
(and in other places too, eg legend). So I can get to the desired <path>
that way but it looks a bit too hacky and fragile. An unambiguous id would be nicer.
Here's why I'm trying to do this: I want my user to be able to enter an 'x' value and get returned the 'y' value of each spline in the chart at the entered 'x'. The only way I can find to do this is to 'walk' the length of the spline curve (obtained from mypath.getTotalLength()) and use the SVG function mypath.getPointAtLength(some length) until I reach the desired 'x' value. If there's a better way to do this with a spline I'd like to know!
来源:https://stackoverflow.com/questions/62251625/highcharts-set-an-id-for-a-spline-data-set