0
我嘗試將數字設置爲轉換組的屬性。調用函數(d){} in .attr()
但是,要設置數字,我需要訪問數據。
我發現用function(d){}
訪問數據是不可能的。
如何訪問.attr()
中的數據?
var xCol = 'month'
var wraps = g.selectAll('.wrap').data(data);
wraps.enter().append('g')
.attr('class', 'wrap')
.attr('transform', 'translate('+function(d){return xScale(d[xCol])}()+', '+ (-margin.top)+')')
>>>index.js:132 Uncaught TypeError: Cannot read property 'month' of undefined
我想讓幾組.wrap
和各組
畫吧,但我不知道該數據轉發到子元素。
var bars = wraps.selectAll('.bar').data(function(d){return d});
bars.enter().append('rect')
.attr('class', 'bar')
.attr('x', function(d){return xScale(d.d[xCol])})
...