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


d3.js line.defined()用法及代码示例

d3.line.defined()方法使您可以指定是否有为给定数据点定义的数据。如果此方法返回false,则表示存在数据点,否则为true。

用法:

d3.line.defined(data_point);

Parameters: 

  • data_point:data_point被检查。

返回值:此方法返回一个布尔值。

范例1:在此示例中,我们将使用此方法省略一些要点。



<!DOCTYPE html> 
<html> 
<meta charset="utf-8"> 
<head> 
  <title>d3.line.defined()</title> 
</head> 
<script src= 
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"> 
</script> 
  
<body> 
    <h1 style="text-align:center;  
               color:green;"> 
       GeeksforGeeks 
    </h1> 
  <center> 
    <svg id="gfg" width="400" height="400"> 
      </svg> 
</center> 
  <script> 
var points = [ 
      {xpoint:25,  ypoint:150}, 
      {xpoint:75,  ypoint:85}, 
      {xpoint:100, ypoint:115}, 
      {xpoint:125, ypoint:55}, 
      {xpoint:150, ypoint:105}, 
      {xpoint:175, ypoint:25}, 
      {xpoint:200, ypoint:155}, 
      {xpoint:225, ypoint:15}, 
      {xpoint:250, ypoint:135}, 
    ]; 
  
var Gen = d3.line() 
  .x((p) => p.xpoint) 
  .y((p) => p.ypoint) 
  .defined(((d, i) => i != 4)); 
  
d3.select("#gfg") 
  .append("path") 
  .attr("d", Gen(points)) 
  .attr("fill", "none") 
  .attr("stroke", "green"); 
  
</script> 
</body> 
</html>

输出:

范例2:在此示例中,我们将使用此方法省略空点。

<!DOCTYPE html> 
<html> 
<meta charset="utf-8"> 
<head> 
  <title>d3.line.defined()</title> 
</head> 
<script src= 
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"> 
</script> 
  
<body> 
    <h1 style="text-align:center; 
        color:green;"> 
        GeeksforGeeks 
    </h1> 
  <center> 
    <svg id="gfg" width="400" height="400"> 
    </svg> 
</center> 
  <script> 
var points = [ 
      {xpoint:25,  ypoint:150}, 
      {xpoint:75,  ypoint:null}, 
      {xpoint:100, ypoint:115}, 
      {xpoint:125, ypoint:55}, 
      {xpoint:150, ypoint:null}, 
      {xpoint:175, ypoint:25}, 
      {xpoint:200, ypoint:155}, 
      {xpoint:225, ypoint:15}, 
      {xpoint:250, ypoint:135}, 
    ]; 
  
var Gen = d3.line() 
  .x((p) => p.xpoint) 
  .y((p) => p.ypoint) 
  .defined(function (d) { return d.ypoint !== null; }); 
  
d3.select("#gfg") 
  .append("path") 
  .attr("d", Gen(points)) 
  .attr("fill", "none") 
  .attr("stroke", "green"); 
  
</script> 
</body> 
</html>

输出:




相关用法


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