D3:多系列图表不适用于上一版本

时间:2015-11-09 15:02:45

标签: javascript d3.js nvd3.js

我试图创建一个多系列折线图,我找到了这个有用的例子http://bl.ocks.org/bobmonteverde/2070069

问题是这对于先前版本的d3(版本2)和上一版本(版本3)的一些问题是有效的。调试后,我发现错误在D3的转换函数中,当它尝试transition = node[ns][id0]并且node[ns]未定义时。我有这个工作的jsfiddle http://jsfiddle.net/jupa_aguilar/0L1pyw8u/。我还观察到,对于d3.v2.js,d3_selectionPrototype.transition是:

d3_selectionPrototype.transition = function() {
var subgroups = [], subgroup, node;
for (var j = -1, m = this.length; ++j < m; ) {
  subgroups.push(subgroup = []);
  for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
    subgroup.push((node = group[i]) ? {
      node: node,
      delay: d3_transitionDelay,
      duration: d3_transitionDuration
    } : null);
  }
}
return d3_transition(subgroups, d3_transitionId || ++d3_transitionNextId, Date.now());};

对于d3.v3.js:

d3_transitionPrototype.transition = function() {
var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
for (var j = 0, m = this.length; j < m; j++) {
  subgroups.push(subgroup = []);
  for (var group = this[j], i = 0, n = group.length; i < n; i++) {
    if (node = group[i]) {
      transition = node[ns][id0];
      d3_transitionNode(node, i, ns, id1, {
        time: transition.time,
        ease: transition.ease,
        delay: transition.delay + transition.duration,
        duration: transition.duration
      });
    }
    subgroup.push(node);
  }
}
return d3_transition(subgroups, ns, id1);};

有关于此的任何想法吗?

1 个答案:

答案 0 :(得分:0)

最好用D3最新版本启动你的代码.D3最新版本的最新版本有一些变化。

因此,请使用您的舒适版本从互联网上查看示例并尝试实施该示例,而不是自行将旧版本图表转换为新版本。

如果您想查看示例,请访问此处 Multi Series Line chart with D3 V3