【发布时间】:2014-03-02 03:03:56
【问题描述】:
我正在使用 d3 创建一个“趋势”分析条形图。该图表在中间有一个 X 轴,条形可以在该轴上方或下方延伸以表示百分比变化。我通过使用 3 个刻度来做到这一点 - X 轴的序数和 Y 轴的两个线性刻度。 两个线性刻度的使用是我不确定的。这似乎不雅,只是“不对”。
有问题的秤:
this.pyscale.domain([0, 1]);
this.pyscale.rangeRound([this.height/2, 0]);
this.nyscale.domain([-1, 0]);
this.nyscale.rangeRound([this.height, this.height/2]);
与绘制条形相关的函数:
bar.append("rect")
.attr("y", function(d) {
if (d[that.ycol] >= 0) {
return that.pyscale(d[that.ycol]);
}
return that.height/2;
})
.attr("height", function(d) {
if (d[that.ycol] >= 0) {
return that.height/2 - that.pyscale(d[that.ycol]);
}
return that.nyscale(d[that.ycol]) - that.height/2;
})
.attr("width", this.xscale.rangeBand())
这是一个不错的方法吗?或者有没有更优雅的方式使用我缺少的 Y 刻度?
感谢您的宝贵时间。
【问题讨论】:
标签: javascript d3.js visualization