0

I try to get 'path' to make use of it with .getTotalLength() .getPointAtLength() methods.

I try the following out of not knowing well enough SVG stuff:

// Declare the line generator.
const line = d3
  .line()
  .x((d) => x(d.xpoint))
  .y((d) => y(d.ypoint))
  .curve(d3.curveCatmullRom.alpha(0.5));

// Append a path for the line.
svg
  .append('path')
  .attr('fill', 'none')
  .attr('stroke', 'steelblue')
  .attr('stroke-width', 1.5)
  .attr('d', line(data));

let path = document.querySelector('path');
console.log(path);

But path is null.

How can I do this correctly?

2
  • So, the question has nothing to do with .getTotalLength() and getPointAtLength(), but the issue of getting a DOM element? Try reading the documentation for or a tutorial about d3.js. Alternatively you can write the SVG code by hand.
    – chrwahl
    Commented Jul 3 at 14:35
  • It seems like you haven't created a parent svg element so <path> is null Commented Jul 3 at 14:53

0

Browse other questions tagged or ask your own question.