【问题标题】:Translating mouse-over text in NVD3.js在 NVD3.js 中翻译鼠标悬停的文本
【发布时间】:2015-11-02 09:17:27
【问题描述】:

我正在使用一些带有优秀 nvd3 库的堆叠条形图(这些:http://nvd3.org/examples/multiBar.html

我有一个问题。我想要鼠标悬停的工具提示,但我需要将“on”这个词翻译成另一种语言。我找不到任何有关如何执行此操作的文档,而且我似乎无法在源代码中找到它。

有人知道吗?

【问题讨论】:

  • 以前没有处理过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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多