0

I'm using some stacked bar diagrams with the excellent nvd3 library (These: http://nvd3.org/examples/multiBar.html)

I have a problem though. I want the mouse-over tooltip just as it is, but I need to translate the word 'on' into another language. I can't find any documentation on how to do that and I can't seem to find it in the source code.

Anyone have a clue?

Christoffer
  • 7,470
  • 9
  • 39
  • 55
  • 1
    Haven't dealt with nvd3 before, so there may be a built in command for this (tooltip parameter?), but you could also dive into the nvd3 [source code](http://nvd3.org/assets/js/nv.d3.js). Specifically, line #8003: `'

    ' + y + ' on ' + x + '

    '`.
    – JSBob Aug 10 '15 at 15:38
  • 1
    According to [this](http://stackoverflow.com/questions/12416508/nvd3-piechart-js-how-to-edit-the-tooltip) other question there is a built in function to set the tooltip. – JSBob Aug 10 '15 at 15:40

1 Answers1

1

In versions 1.7.1 and below (which I assume you're using), you can use 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>'
});

See this plunk for an example: http://plnkr.co/edit/YxZKDBqVWhtxryUSMwjk?p=preview

If you use 1.8.1, the same could be accomplished like this:

// 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>'
});

As shown in this plunk: http://plnkr.co/edit/ZYsjygDJkHSit50Rh3sZ?p=preview

Lucas
  • 1,359
  • 7
  • 16