当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js area.curve()用法及代码示例


这个d3.area.curve()方法用于绘制该区域的曲线。 D3.js提供了一些曲线工厂,可用于提供不同的曲线。

用法:

d3.area.curve(curve_factory)

参数:该函数接受如上所述和以下描述的单个参数。

  • curve_factory:此参数是曲线的类型。

返回值:此方法没有返回值。

范例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>

输出:

范例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>

输出:




相关用法


注:本文由纯净天空筛选整理自taran910大神的英文原创作品 D3.js area.curve() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。