【发布时间】:2017-11-07 10:30:32
【问题描述】:
我正在尝试在 D3 的图表中绘制垂直线标记。它模仿了这个例子:https://bl.ocks.org/mbostock/34f08d5e11952a80609169b7917d4172
我的问题是,在我画线后,当我缩放/滚动图表时它不会移动。一个例子如下所示:
目前,我将其计算为d3.area()。
this.pastDateArea = d3.area()
.x(function(d) { return this.x(this.props.pastDate.toDate()) }.bind(this))
.y0(0)
.y1(function(d) { return this.height }.bind(this))
附加为
var pastDateData = [{x:this.props.pastDate.toDate(), y:150}]
this.focus.append("path")
.datum(pastDateData)
.attr("class", "area")
.attr("d", this.pastDateArea)
并使用
进行缩放/画笔//zoom
var t = d3.event.transform;
this.x.domain(t.rescaleX(this.x2).domain());
//brush
this.svg.select(".zoom").call(this.zoom.transform, d3.zoomIdentity
.scale(this.width / (s[1] - s[0]))
.translate(-s[0], 0));
我知道有与此类似的问题(即Draw a vertical line representing the current date in d3 gantt chart),但没有一个包含我在图表中的缩放/平移功能。
如果您需要更多信息,请告诉我,谢谢!
【问题讨论】:
标签: javascript css d3.js