【发布时间】:2015-07-07 03:01:18
【问题描述】:
I have put together a D3 line chart 并使用剪辑路径/剪辑添加阈值编码。我面临的唯一问题是我无法在此图表中添加工具提示。当我将鼠标悬停在图表中的任意位置并且图表上相应的 y 轴值显示在工具提示中时,我想要一个工具提示。
我已使用此example by Mike Bostock 添加阈值编码。
var line = d3.svg.line()
.interpolate("basis")
.x(function(d) { return _config.xScale(d.vtc); })
.y(function(d) { return _config.yScale(d.values); });
svg.append("clipPath")
.attr("id", "clip-above")
.append("rect")
.attr("width", _config.width)
.attr("height", _config.yScale(55));
svg.append("clipPath")
.attr("id", "clip-below")
.append("rect")
.attr("y", _config.yScale(55))
.attr("width", _config.width)
.attr("height", _config.height - _config.yScale(55));
svg.selectAll(".line")
.data(["above", "below"])
.enter().append("path")
.attr("class", function(d) { return "line " + d; })
.attr("clip-path", function(d) { return "url(#clip-" + d + ")"; })
.datum(data)
.attr("d", line);
我不知道如何为这个特定图表添加工具提示,因为路径上有一个剪辑矩形,并且路径被分解为上方和下方段以提供颜色效果。
我们是否有一种统一的方式来将工具提示添加到正常路径和这个?如果是,我想知道一些我可以查看的来源/链接。
类似于this,但没有那么复杂(没有任何指示符,只有工具提示)
【问题讨论】:
标签: javascript d3.js charts data-visualization linechart