📜  D3.js log.rangeRound()函数

📅  最后修改于: 2022-05-13 01:56:48.384000             🧑  作者: Mango

D3.js log.rangeRound()函数

log.rangeRound()函数用于将刻度范围设置为指定的值数组,同时它在内部将插值器设置为 interpolatorRound。

句法:

log.rangeRound([range]);

参数:此函数采用上面给出并在下面描述的单个参数。

  • [范围]:包含指定域范围的数组。

返回值:此函数不返回任何值。

示例 1:

HTML


  

    
    
    
    

  

    GeekforGeeks
  
    log.rangeRound() Function
  
    
        var log = d3.scaleLog()
            // Domain
            .domain([1, 10])
  
            // Range for the domain
            .rangeRound([10, 20, 30, 40, 50, 60, 70, 80, 90]);
              
        document.write("<h3>log(1.0): " + log(1.0) + "</h3>");
        document.write("<h3>log(2.5): " + log(2.5) + "</h3>");
        document.write("<h3>log(4): " + log(4) + "</h3>");
        document.write("<h3>log(4.5): " + log(4.5) + "</h3>");
        document.write("<h3>log(1.5): " + log(1.5) + "</h3>");
    log(1.0): 10log(2.5): 14log(4): 16log(4.5): 17log(1.5): 12

  


HTML


  

    
    
    
    

  

    GeekforGeeks
  
    log.rangeRound() Function
  
    
        var log = d3.scaleLog()
            // Domain
            .domain([1, 10])
            // Range for the domain
            .rangeRound([0, 960]);
  
        document.write("<br/><div style=float:left;>");
        document.write("<p> With rangeRound()</p>");
        document.write("<h3>" + log(1.5) + "</h3>");
        document.write("<h3>" + log(2.5) + "</h3>");
        document.write("<h3>" + log(3.5) + "</h3>");
        document.write("<h3>" + log(4.5) + "</h3>");
        document.write("<h3>" + log(8.5) + "</h3>");
        document.write(
            "<h3>" + log(10.5) + "</h3></div>");
  
        var log = d3.scaleLog()
            // Domain
            .domain([1, 10])
            // Range for the domain
            .range([0, 960]);
  
        document.write(
          "<div style=margin-left:10px;float:left;>");
        document.write("<p> Without rangeRound()</p>");
        document.write("<h3>" + log(1.5) + "</h3>");
        document.write("<h3>" + log(2.5) + "</h3>");
        document.write("<h3>" + log(3.5) + "</h3>");
        document.write("<h3>" + log(4.5) + "</h3>");
        document.write("<h3>" + log(8.5) + "</h3>");
        document.write(
            "<h3>" + log(10.5) + "</h3></div>");
     With rangeRound()169382522627892980 Without rangeRound()169.04760869345398382.0224083251561522.3053225762645627.0840132243299892.2421686857209980.3417271071405

  


输出:

示例 2:

HTML



  

    
    
    
    

  

    GeekforGeeks
  
    log.rangeRound() Function
  
    
        var log = d3.scaleLog()
            // Domain
            .domain([1, 10])
            // Range for the domain
            .rangeRound([0, 960]);
  
        document.write("<br/><div style=float:left;>");
        document.write("<p> With rangeRound()</p>");
        document.write("<h3>" + log(1.5) + "</h3>");
        document.write("<h3>" + log(2.5) + "</h3>");
        document.write("<h3>" + log(3.5) + "</h3>");
        document.write("<h3>" + log(4.5) + "</h3>");
        document.write("<h3>" + log(8.5) + "</h3>");
        document.write(
            "<h3>" + log(10.5) + "</h3></div>");
  
        var log = d3.scaleLog()
            // Domain
            .domain([1, 10])
            // Range for the domain
            .range([0, 960]);
  
        document.write(
          "<div style=margin-left:10px;float:left;>");
        document.write("<p> Without rangeRound()</p>");
        document.write("<h3>" + log(1.5) + "</h3>");
        document.write("<h3>" + log(2.5) + "</h3>");
        document.write("<h3>" + log(3.5) + "</h3>");
        document.write("<h3>" + log(4.5) + "</h3>");
        document.write("<h3>" + log(8.5) + "</h3>");
        document.write(
            "<h3>" + log(10.5) + "</h3></div>");
     With rangeRound()169382522627892980 Without rangeRound()169.04760869345398382.0224083251561522.3053225762645627.0840132243299892.2421686857209980.3417271071405

  

输出: