HighCharts: set an id for a spline data set?

纵饮孤独 提交于 2020-06-17 09:45:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!