D3.js curveMonotoneX() Method Last Updated : 09 Sep, 2020 Suggest changes Share Like Article Like Report The d3.curveMonotoneX interpolator assumes that the data is sorted according to the x coordinates otherwise sort the data accordingly. This curve method produces a cubic spline that preserves monotonicity in y, assuming monotonicity in x. Syntax: d3.curveMonotoneX() Parameters: This method does not accept any parameters. Return Value: This method does not return any value. Example 1: html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src= "https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"> </script> </head> <body> <h1 style="text-align:center; color:green;"> GeeksforGeeks </h1> <center> <svg id="gfg" width="250" height="250"></svg> </center> <script> var data = [ {x: 0, y: 0}, {x: 1, y: 3}, {x: 2, y: 15}, {x: 5, y: 1}, {x: 6, y: 15}, {x: 7, y: 5}, {x: 8, y: 19}]; var xScale = d3.scaleLinear() .domain([0, 8]).range([25, 200]); var yScale = d3.scaleLinear() .domain([0, 20]).range([200, 25]); var line = d3.line() .x((d) => xScale(d.x)) .y((d) => yScale(d.y)) .curve(d3.curveMonotoneX); d3.select("#gfg") .append("path") .attr("d", line(data)) .attr("fill", "none") .attr("stroke", "green"); </script> </body> </html> Output: Example 2: Sorting the unsorted points by the x-axis then rendering the curve. html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src= "https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"> </script> </head> <body> <h1 style="text-align:center; color:green;"> GeeksforGeeks </h1> <center> <svg id="gfg" width="250" height="200"></svg> </center> <script> var points = [ {xpoint: 75, ypoint: 150}, {xpoint: 25, ypoint: 5}, {xpoint: 150, ypoint: 115}, {xpoint: 100, ypoint: 5}, {xpoint: 200, ypoint: 150}]; // Sorting the points by x axis points.sort((a, b) => a.xpoint - b.xpoint); var Gen = d3.line() .x((p) => p.xpoint) .y((p) => p.ypoint) .curve(d3.curveMonotoneX); d3.select("#gfg") .append("path") .attr("d", Gen(points)) .attr("fill", "none") .attr("stroke", "green"); </script> </body> </html> Output: T taran910 Follow Article Tags : JavaScript D3.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like