The line.y() method sets or returns the y accessor point of the line. If y is provided, it must be a number or a function that returns a number.
Syntax:
d3.line.y();
Parameters:
- y-point: This method takes a y-point that can be set from the points array.
Return Value: This method returns the y accessor point of the line.
Example 1: Setting the y-point using this method. For x-points here we have used line.x() function.
HTML
<!DOCTYPE html> < html > < meta charset = "utf-8" > < head > < script src = </ script > </ head > < body > < h1 style = "text-align:center; color:green;" > neveropen </ h1 > < center > < svg id = "gfg" width = "200" height = "200" > </ svg > </ center > < script > var points = [ { xpoint: 25, ypoint: 150 }, { xpoint: 75, ypoint: 85 }, { xpoint: 100, ypoint: 115 }, { xpoint: 175, ypoint: 25 }]; var Gen = d3.line() .x((p) => p.xpoint) // Setting the y-point .y((p) => p.ypoint); d3.select("#gfg") .append("path") .attr("d", Gen(points)) .attr("fill", "none") .attr("stroke", "green"); </ script > </ body > </ html > |
Output:
Example 2: Getting the function for y points.
HTML
<!DOCTYPE html> < html > < meta charset = "utf-8" > < head > < script src = </ script > </ head > < body > < h1 style = "text-align:center; color:green;" > neveropen </ h1 > < center > < svg id = "gfg" width = "200" height = "200" ></ svg > </ center > < script > var points = [ { xpoint: 25, ypoint: 150 }, { xpoint: 75, ypoint: 85 }, { xpoint: 100, ypoint: 115 }, { xpoint: 175, ypoint: 25 }]; var Gen = d3.line() .x((p) => p.xpoint) .y((p) => p.ypoint); d3.select("#gfg") .append("path") .attr("d", Gen(points)) .attr("fill", "none") .attr("stroke", "green"); console.log(Gen.y()); console.log(Gen.y) </ script > </ body > </ html > |
Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!