método d3.area.curve()
Sintaxis:
d3.area.curve(curve_factory)
Parámetros:
- curve_factory: Este parámetro es el
Valor de retorno: este método no tiene valor de retorno.
Ejemplo 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> <h3 style="text-align: center;"> D3.js | d3.area.curve() Method </h3> <center> <svg id="gfg" width="250" height="200"></svg> </center> <script> var points = [ {xpoint: 25, ypoint: 150}, {xpoint: 75, ypoint: 50}, {xpoint: 100, ypoint: 150}, {xpoint: 100, ypoint: 50}, {xpoint: 200, ypoint: 150}]; var Gen = d3.area() .x((p) => p.xpoint) .y0((p) => p.ypoint/2) .y1((p) => p.ypoint) // Using curveBasis .curve(d3.curveBasis); d3.select("#gfg") .append("path") .attr("d", Gen(points)) .attr("fill", "green") .attr("stroke", "black"); </script> </body> </html>
Producción:
Ejemplo 2:
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> <h3 style="text-align: center;"> D3.js | d3.area.curve() Method </h3> <center> <svg id="gfg" width="250" height="200"></svg> </center> <script> var points = [ {xpoint: 25, ypoint: 150}, {xpoint: 75, ypoint: 50}, {xpoint: 100, ypoint: 150}, {xpoint: 100, ypoint: 50}, {xpoint: 200, ypoint: 150}]; var Gen = d3.area() .x((p) => p.xpoint) .y0((p) => p.ypoint/2) .y1((p) => p.ypoint) // Using curveCardinal .curve(d3.curveCardinal); d3.select("#gfg") .append("path") .attr("d", Gen(points)) .attr("fill", "green") .attr("stroke", "black"); </script> </body> </html>
Producción: