如何通过数据连接将多个x轴添加到d3图表
how to add multiple x axes to d3 chart via data join?
我试图在一次使用d3创建几个图表-代码在这里:http://jsfiddle.net/jgilfillan/W85ut/
我有一个包含这些对象的数组bulletDataX
function BulletObject(name, actual, target, ranges, bulletWidth) {
this.name = name;
this.actual = actual;
this.target = target;
this.ranges = ranges;
this.maxX = ranges[2];
this.bulletWidth = bulletWidth;
this.scale = d3.scale.linear().domain([0, this.maxX]).range([0, this.bulletWidth]);
this.xAxis = d3.svg.axis().scale(this.scale).orient("bottom");
}
这是我试图让工作的代码…
//axes??? not working
svg.selectAll(".xaxis")
.data(bulletDataX)
.enter()
.append("g")
.attr("id", function(d) { return d.name; })
.attr("class", "x axis")
.attr("transform", function(d, i) { return "translate(0, " + ((bulletHeight + bulletPadding) * i + .25 * bulletHeight).toString() + ")"; })
.call(function(d, i) { return d.xAxis; });
我知道我必须摆弄一下transform属性,但我甚至不能得到轴显示。我认为问题是与.call(function(d, i) { return d.xAxis; })
,但我不知道如何让它的工作。
call
方法不提供d, i
参数。相反,它:
调用指定的函数一次,传入当前选择以及任何可选参数。
参见API文档:selection。函数调用([…],参数)
您可以尝试使用each
代替。:
为当前元素中的每个元素调用指定的函数选择,传入当前数据d和索引i,并使用
this
当前DOM元素的上下文。
参见API文档:selection.each(function)
下面是一个代码示例:
.each(function (d, i) {
return d.xAxis(d3.select(this));
});
相关文章:
- 如何在d3上的图形中添加放大和缩小按钮
- D3.JS向rect添加缩放和列表项
- 在链接d3强制布局中添加和删除类
- 添加新数据时D3.JS条形图列偏移量
- 如何在d3.js饼图或圆环图中添加阴影
- 在d3中向DOM元素添加了图像,但现在它赢得了't过渡
- 向d3圆添加文本
- d3.js:如何为图上的散点添加标签
- 在d3.js圆中添加阴影效果
- 将工具提示添加到d3散点图中
- 如何将图标添加到D3轴
- 向Graph中的所有d3.js数据点添加唯一链接
- 如何在D3.js中添加箭头链接
- 在D3散点图圆上添加标签
- 如何用D3添加一个简单的圆弧
- 向 d3 图表添加时间
- 如何添加D3 Force的起始位置?
- 添加d3 svg.selectAll(".foo").style("fill",
- 添加d3标签不工作
- 在RAW中添加d3.js交互式可缩放树图