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


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


D3.js中的d3.hcl()函数用于构造新的HCL颜色,并返回指定颜色的HCL属性作为该函数的参数。

用法:

d3.hcl(color);

参数:此函数接受用于指定CSS颜色的单个参数颜色。


返回值:该函数返回指定CSS颜色的HCL属性作为该函数的参数。

以下程序说明了D3.js中的d3.hcl()函数:

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>d3.hcl() function</title> 
  
    <script src='https://d3js.org/d3.v4.min.js'></script> 
</head> 
  
<body> 
    <script> 
          
        // Calling the d3.hcl() function fuction 
        // with some parameters 
        var color1 = d3.hcl("red"); 
        var color2 = d3.hcl("green"); 
        var color3 = d3.hcl("blue"); 
        
        // Getting the HCL properties 
        console.log(color1); 
        console.log(color2); 
        console.log(color3); 
    </script> 
</body> 
  
</html>

输出:

{"h":39.99901061253295,"c":104.55176567686985,"l":53.24079414130722,"opacity":1}
{"h":136.01595303206318,"c":71.8500499715016,"l":46.22743146876261,"opacity":1}
{"h":306.2849380699878,"c":133.80761485376166,"l":32.297010932850725,"opacity":1}

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>d3.hcl() function</title> 
  
    <script src='https://d3js.org/d3.v4.min.js'></script> 
</head> 
  
<body> 
    <script> 
          
        // Calling the d3.hcl() function fuction 
        // without any parameters 
        var color = d3.hcl(); 
        
        // Getting the HCL values 
        console.log(color); 
    </script> 
</body> 
  
</html>

输出:

{"h":null,"c":null,"l":null,"opacity":1}

参考: https://devdocs.io/d3~5/d3-color#hcl



相关用法


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