【问题标题】:nvd3 LineChart tooltip not worksnvd3 LineChart 工具提示不起作用
【发布时间】:2014-07-07 13:21:09
【问题描述】:

在这个演示中http://nvd3.org/livecode/index.html#codemirrorNav 只需将数据更改为

function() {

  return [
    {
      values: [{x:23,y:9,},{x:22,y:6,},{x:21,y:6,},{x:20,y:10,},{x:19,y:19,},{x:18,y:26,},{x:17,y:30,},{x:16,y:41,},{x:15,y:49,},{x:14,y:31,},{x:13,y:48,},{x:12,y:7,},{x:11,y:26,},{x:10,y:47,},{x:9,y:35,},{x:8,y:20,},{x:7,y:25,},{x:6,y:1,},{x:0,y:1,}],
      key: 'A',
      color: '#ff7f0e'
    },
    {
      values: [{x:22,y:6,},{x:20,y:3,},{x:19,y:1,},{x:18,y:7,},{x:17,y:8,},{x:16,y:15,},{x:15,y:22,},{x:14,y:9,},{x:13,y:10,},{x:12,y:16,},{x:11,y:27,},{x:10,y:34,},{x:9,y:57,},{x:8,y:162,},{x:7,y:102,},{x:6,y:3,},{x:3,y:1,},{x:0,y:1,}],
      key: 'B',
      color: '#2ca02c'
    }
  ];
}

工具提示被破坏了。所以,为什么?

【问题讨论】:

    标签: javascript d3.js nvd3.js


    【解决方案1】:

    这是因为 NVD3 期望数据是有序的,如果您将数据更改为类似

    function() {
    
      return [
        {
          values: [{x:21,y:9,},{x:22,y:6,},{x:23,y:6,}],
          key: 'A',
          color: '#ff7f0e'
        },
        {
          values: [{x:21,y:6,},{x:22,y:3,},{x:23,y:1,}],
          key: 'B',
          color: '#2ca02c'
        }
      ];
    }
    

    它有效。您必须使用.sort()在服务器端或javascript 上订购您的数据

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      相关资源
      最近更新 更多