custom tooltip on cumulativeLineChart in nvd3

六月ゝ 毕业季﹏ 提交于 2019-11-30 17:09:51

问题


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.


回答1:


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!




回答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.



来源:https://stackoverflow.com/questions/17319732/custom-tooltip-on-cumulativelinechart-in-nvd3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!