0
這是我用d3.js製作的圖表。我希望我的酒吧以tick值爲中心 - 就像每個酒吧(3酒吧)的中間酒吧應該與月份名稱一致。有沒有辦法做到這一點優雅?如果您需要關於數據集或圖表功能的更多信息,請告訴我們。d3js - 列圖 - 數據點對齊
一些有用的代碼
this.container.selectAll('g.container')
.data(this.data)
.enter().append('g')
.attr('class', 'container')
.attr('transform', function(d, i){
console.log(d.dimension, this)
var x = self.margin.left + self.xScale(d.dimension.value);
var y = self.margin.top;
return 'translate('+ x + ',' + y +')'
});
this.bars = this.container.selectAll('g.container')
.selectAll('rect.bar')
.data(function(d){ return d; })
.enter()
.append('rect')
.attr('class', 'bar')
.attr('width', 3)
.attr('height', function(d){
console.log(d.y, d.key, this);
return availableHeight - self.yScale(d.y);
})
.attr('y', function(d){ return self.yScale(d.y); })
.attr('x', function(d, i){ return i * 5 });
我該如何弄清楚這種差異?如果我可以找出我的蜱的定位值,我可以簡單地使用該值 – 2012-07-21 11:16:43
您只需計算兩個連續的「dimension.value」之間的差異即可。據推測這是你的JSON中的東西? – 2012-07-21 11:47:23