【发布时间】:2015-04-10 22:46:18
【问题描述】:
我正在使用 v1.7.1 的 nvd3。我有一个页面,我在其中呈现具有相同配置但不同数据的图表行。我在多折线图上使用交互式工具提示选项。工具提示正在正确呈现,但是当您向下滚动页面时,当您滚动线时,工具提示将呈现在页面顶部的相同位置。前几行似乎将工具提示呈现在适当的位置,但是当您向下滚动时,工具提示就会消失。我尝试使用 tooltipContent (似乎是可用的 api)来操纵位置,但这不起作用。如下所示:
var chartOffset = $(id + ' svg').offset(),
x = chartOffset.left,
y = chartOffset.top;
//chart.tooltip.position({"top":top,"left":left});
//chart.interactiveLayer.tooltip.fixedTop(null);
chart.tooltipContent(function (key, x, y, e) {
if (e.value >= 0) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' at ' + x + '</p>';
} else {
return '';
}
});
我也尝试过设置 .nvtooltip 边距的样式,但没有看到修复。
下图显示了工具提示如何与您正在移动的线非常脱节
有解决此问题的提示吗?
这里是完整的 nvd3 图表选项:
var chart = nv.models.lineChart()
.height(height)
.width(width)
.forceY([0, 1])
.x(function (d) {
return new Date(d[0]);
})
.y(function (d) {
return d[1];
})
.color(chartcolors)
.useInteractiveGuideline(true)
.tooltips(true);
chart.xAxis
.axisLabel("")
.tickFormat(function (d) {
return d3.time.format('%x')(new Date(d))
});
chart.yAxis
.axisLabel(yaxisLabel)
.tickFormat(d3.format(',.1%'));
chart.showLegend(true);
var chartOffset = $(id + ' svg').offset(),
x = chartOffset.left,
y = chartOffset.top;
chart.tooltipContent(function (key, x, y, e) {
if (e.value >= 0) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' at ' + x + '</p>';
} else {
return '';
}
});
【问题讨论】: