2016-12-06 77 views
0

我正在Angular 2應用程序中使用D3 Js創建條形圖。獲取d3的錯誤Js

我使用V4.4 D3的並在低於線得到以下錯誤,

。域(d3.range(n))的

var n = 20, // number of samples 
     m = 4; // number of series 

    var data = d3.range(m).map(function() { return d3.range(n).map(Math.random); }); 

    var margin = { top: 20, right: 30, bottom: 30, left: 40 }, 
     width = 960 - margin.left - margin.right, 
     height = 500 - margin.top - margin.bottom; 

    var y = d3.scaleLinear() 
     .domain([0, 1]) 
     .range([height, 0]); 

    var x0 = d3.scaleBand() 
     .domain(d3.range(n)) 
     .range([0, width], .2); 

    var x1 = d3.scaleBand() 
     .domain(d3.range(m)) 
     .range([0, x0.range()]); 

    var z = d3.scaleOrdinal(d3.schemeCategory10); 

錯誤,

error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string[]'. 
Type 'number' is not assignable to type 'string'. 

回答

1

錯誤是告訴你,d3.scaleBand().domain想要一個字符串數組作爲參數,你給它一組數字。只是強制你的號碼字符串如:

d3.scaleBand() 
    .domain(d3.range(N).map((d) => d+"")) 
    .range([0, width], .2);