【问题标题】:Translating mouse-over text in NVD3.js在 NVD3.js 中翻译鼠标悬停的文本
【发布时间】:2015-11-02 09:17:27
【问题描述】:
【问题讨论】:
-
以前没有处理过nvd3,所以可能有一个内置命令(工具提示参数?),但你也可以深入nvd3 source code。具体来说,第 #8003 行:'<p>' + y + ' on ' + x + '</p>'.
-
根据this 其他问题有一个内置函数来设置工具提示。
标签:
javascript
d3.js
nvd3.js
diagrams
【解决方案1】:
在 1.7.1 及以下版本(我假设您正在使用)中,您可以使用 chart.tooltipContent()。
// If you want to change the tooltip format you could edit this function
chart.tooltipContent(function (key, x, y, e, graph) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' en ' + x + '</p>'
});
请参阅此 plunk 示例:http://plnkr.co/edit/YxZKDBqVWhtxryUSMwjk?p=preview
如果你使用 1.8.1,同样可以这样完成:
// If you want to change the tooltip format you could edit this function
chart.tooltip.contentGenerator(function (d) {
return '<h3>' + d.data.key + '</h3>' +
'<p>' + d.data.display.y + ' en ' + new Date(d.data.x).toLocaleDateString() + '</p>'
});
如本文所示:http://plnkr.co/edit/ZYsjygDJkHSit50Rh3sZ?p=preview