javascript - NVD3 线图工具提示不跟随鼠标

标签 javascript date datetime d3.js nvd3.js

我正在使用 NVD3 库生成折线图,并提供了一些数据:

screen shot 2014-10-31 at 13 39 44

screen shot 2014-10-31 at 13 40 25

问题是,交互式指南显示如下(特别注意工具提示):

screen shot 2014-10-31 at 13 35 10

screen shot 2014-10-31 at 13 35 19 请注意,我只在折线图的开始和结束处获得工具提示。

现在,我设置useInteractiveGuideline(false)

screen shot 2014-10-31 at 13 34 59

这确实显示正确,但非常缓慢,我想使用 useInteractiveGuideline(true)

我怀疑这是我代码中的错误。

最佳答案

也许你需要定义

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

下面列出的代码在我们的项目中运行良好:

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)
                    ;
...

希望对您有所帮助! 如果你能为此创建一个 fiddle 会更好。

关于javascript - NVD3 线图工具提示不跟随鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26676380/

相关文章:

javascript - 动态导入 React Hooks

javascript - 使用 d3.js 组合父数据和嵌套数据

javascript - 以一定 Angular 移动,jquery,animate()?

SQL服务器: Get total days between two dates

javascript - 将 "long form"日期时间字符串转换为 javascript 日期对象

python - 将日期+小时转换为时间戳 - pandas/python

Javascript:触发了多个鼠标移出事件

PHP DateTime 类命名空间

c# - 使用 Sqlite 数据库填充包含日期时间列的数据集

javascript - 在javascript中将Json日期转换为 "Date"