Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom tooltip on cumulativeLineChart in nvd3

Tags:

d3.js

nvd3.js

When I hover on the lines on the cumulative line chart I get a tooltip message x value at some y time. I want to edit this message and add more content.

Since in my values array I have json containing {X:x, Y:y, Z:z, Dt:date} I wish to show a custom message listing X/Y/Z at date.

like image 648
ajjain Avatar asked Jun 26 '13 12:06

ajjain


2 Answers

I'm using nvd3 veraion 1.1.15b.

Calling .tooltip() didn't work for me, but calling .tooltipContent() did, as in the following code:

        var chart = nv.models.pieChart()
            .x(function (d) { return d.file; })
            .y(function (d) { return d.size; })
            .tooltipContent(function (key, y, e, graph) {
                return '<h3>' + key + '</h3>' +
                    '<p>' + e.value.toSizeFmt() + '</p>';
            })

As Andrei points out above, the e parameter provides access to the raw values so you can format them, rather than working with y which is already formatted text. Hope this helps!

like image 86
edhenn Avatar answered Nov 05 '22 19:11

edhenn


If you have not found a proper solution yet, here you try this -

nv.addGraph(function() {
    var chart = nv.models.cumulativeLineChart().x(function(d) {
        return d[0]
    }).y(function(d) {
        return d[1]
    }).color(d3.scale.category10().range()).tooltip(function(key, x, y, e, graph) {
        return '<h3>' + key + ' Custom Text Here ' + x + '</h3> here' + '<p> or here ,' + y + '</p>'
    });
});

Hope it helps.

like image 2
shabeer90 Avatar answered Nov 05 '22 17:11

shabeer90