【问题标题】:Converting from D3js 2.4.4 to 3.5.5从 D3js 2.4.4 转换为 3.5.5
【发布时间】:2015-06-05 21:39:02
【问题描述】:

该示例使用 D3js 2.4.4 运行:http://mbostock.github.io/d3/talk/20111018/area-gradient.html 我想让它运行 3.5.5 版

我得到的第一个错误是

TypeError: x 不是函数/第 52 行

.attr("x", x(0))

我应该改变什么?

一些进展

看起来第一个问题是 D3.time 来自分离的 D3.time.js,在将 D3.js 替换为 3.5.5 版本后我仍然包含它。 我现在已经删除了 d3.time.js 和 d3.csv.js 的 html 包含。 但现在我明白了:

TypeError: d3.event.transform is not a function //第 110 行

d3.event.transform(x);

【问题讨论】:

  • 详细讨论了在版本 3 下运行此示例here
  • 作为一个健全的检查 here's the code 从那个帖子工作。
  • 谢谢,我已经看过这篇文章,但健全性检查有助于找到一些缺失的细节。

标签: javascript svg d3.js


【解决方案1】:

在这里找到的解决方案: https://groups.google.com/forum/#!topic/d3-js/6p7Lbnz-jRQ

此处的完整性检查代码:http://plnkr.co/edit/b8yO66lazDzIQ0Wf3RRM?p=preview

变化

  1. 将 svg.append('svg:rect') 分配给一个变量。 var rect = svg.append("svg:rect") ...
  2. 评论/删除行.call(d3.behavior.zoom().on("zoom", zoom))
  3. 使用行定义域之后的绑定事件 rect.call(d3.behavior.zoom().x(x).on("zoom", zoom));。 !请注意这一新行中的附加 .x(x)
  4. function zoom(){...} 中注释/删除行d3.event.transform(x);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 2014-12-23
    • 2012-10-27
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多