custom tooltip on cumulativeLineChart in nvd3
Asked Answered
O

2

5

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.

Overage answered 26/6, 2013 at 12:15 Comment(1)
You could try editing it in the cumulativeLineChart.js. Add you string in line 25 . Might not be the best way, but a solution to your problem.Superstratum
V
6

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!

Verlinevermeer answered 13/3, 2014 at 22:37 Comment(0)
S
2

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.

Superstratum answered 30/7, 2013 at 15:3 Comment(1)
Great, this worked perfectly for me. Just to add a bit of info, the additional data for each data node can be accessed through the 'e' parameter, e.point.Z would get Z's value.Apodictic

© 2022 - 2024 — McMap. All rights reserved.