我正在尝试使用SVG和polyline制作图表,并为其分配点。这一部分没有问题,但是由于我对Web开发还很陌生,我在制作交互式内容时遇到了困难。
我想在鼠标悬停在某个X值上时,在工具提示中显示该点的Y值。我已经成功创建了工具提示,但不知道如何获取Y值,是否有好的方法可以做到这一点?
另外,我正在尝试对polyline进行动画处理,使其看起来像是实际绘制出来的,而不仅仅是在读取坐标后出现在屏幕上。我在SVG路径中找到了类似的东西:https://jakearchibald.com/2013/animated-line-drawing-svg/
var path = document.querySelector('.squiggle-animated path');
var length = path.getTotalLength();
// Clear any previous transition
path.style.transition = path.style.WebkitTransition =
'none';
// Set up the starting positions
path.style.strokeDasharray = length + ' ' + length;
path.style.strokeDashoffset = length;
// Trigger a layout so styles are calculated & the browser
// picks up the starting position before animating
path.getBoundingClientRect();
// Define our transition
path.style.transition = path.style.WebkitTransition = 'stroke-dashoffset 2s ease-in-out';
// Go!
path.style.strokeDashoffset = '0';
这是路径动画代码的样子,但由于某些原因,在折线上无法正常工作。这是因为路径不等于折线吗?