NVD3 linechart tooltips not following the mouse

安稳与你 提交于 2019-12-07 18:40:09

问题


I'm using the NVD3 library to generate a linechart, and gave some data:

The problem is, the interactive guideline shows up like this (specifically note the tooltips):

Note that I only get a tooltip at the start and end of the linechart.

Now, I set useInteractiveGuideline(false)

This DOES show up correctly, but is very laggy and I'd like to use useInteractiveGuideline(true).

Is suspect this is a bug in my code.


回答1:


maybe you need to define the

.x(function (d) {
    return xValues.indexOf(d.x);
 })

the code listed below works fine in our project:

nv.addGraph(function () {
                    var chart = nv.models.lineChart()
                            .margin({bottom: 20})
                            .x(function (d) {
                                return xValues.indexOf(d.x);
                            })
                            .useInteractiveGuideline(false)
                                .forceY([-10, 40])
                            .tooltipContent(function (key, x, y, e) {
                                return '<h3>' + key + '</h3>' +
                                    '<p>' + e.point.y + ' at ' + x + '</p>';
                            })
                        ;

                    chart.xAxis
                        //.axisLabel($translate.instant('loadTests.overview.testRuns.grid.startOn'))
                        .showMaxMin(true)
                        .tickFormat(function (d) {
                            if (typeof(d) === 'number' && d >= 0 && d < xValues.length) {
                                return d3.time.format('%m/%d')(new Date(1 * xValues[d]));
                            }
                            return 0;
                        })
                        .tickValues(xValues)
                    ;
...

hope it helps! it would be better if you could create a fiddle for this.



来源:https://stackoverflow.com/questions/26676380/nvd3-linechart-tooltips-not-following-the-mouse

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