交互式折线图显示xDomain外部的数据点

时间:2014-10-20 16:12:41

标签: javascript charts nvd3.js

我需要制作一个多个系列的交互式折线图,并且我使用NVD3为其启用了交互性(useIntractiveGuidline)。但是,如果图表的xDomain比数据点跨度更窄,则似乎存在问题。考虑一个例子。您有3个数据系列,X点​​1,2和3.您的图表的X范围为[ 1.1, 4 ]。现在,如果你移动鼠标稍微调整图表的Y轴,你会看到 - 即使你使用clipEdge - NVD3仍然显示数据点和带有值的弹出窗口:

enter image description here

我为这个错误编译了一个JSFiddle:http://jsfiddle.net/e6kwrqdw/。我的JavaScript代码:

var data = [
    {
        key: 's#1',
        values: [
            { x: 1, y: 5 },
            { x: 2, y: 7 },
            { x: 3, y: 3 }
        ]
    },
    {
        key: 's#2',
        values: [
            { x: 1, y: 4 },
            { x: 2, y: 8 },
            { x: 3, y: 4 }
        ]
    },
    {
        key: 's#3',
        values: [
            { x: 1, y: 1 },
            { x: 2, y: 2 },
            { x: 3, y: 6 }
        ]
    }

];

var chart = nv.models.lineChart()
    .useInteractiveGuideline(true)
    .tooltips(true)
    .margin({ left: 200 })
    .xDomain([ 1.1, 4 ])
    .clipEdge(true)
    .showLegend(true);

d3.select('#chart').datum(data).call(chart);

0 个答案:

没有答案
相关问题