将 d3

编程入门 行业动态 更新时间:2024-10-27 20:35:25
本文介绍了将 d3-tip 与 npm 一起使用:“未捕获的类型错误:无法读取未定义的属性‘节点’"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经安装了 d3": "^3.5.17" 和 "d3-tip": "^0.7.1" 使用 npm (d3-tip 文档.然后在我的 index.js 文件中我有这段代码:

I've installed d3": "^3.5.17" and "d3-tip": "^0.7.1" using npm (d3-tip documentation). Then in my index.js file I have this code:

var d3 = require('d3'); var d3tip = require('d3-tip')(d3); console.log('d3 version', d3.version); var tip = d3tip().attr('class', 'd3-tip').html(function(d) { return "hello world"; })

但是当我使用 browserify 构建索引文件并将其加载到浏览器中时,我看到 var tip 行出现错误:

But when I build the index file with browserify and load it in the browser, I see an error from the var tip line:

index.js:247 Uncaught TypeError: Cannot read property 'node' of undefined

这是来自 d3-tip 源代码中的这个函数:

This is coming from this function in the d3-tip source code:

function getSVGNode(el) { el = el.node() if(el.tagName.toLowerCase() === 'svg') return el return el.ownerSVGElement }

看起来这个函数是期望一个节点被传递给它?但这是从哪里来的?

It looks like this function is expecting a node to be passed to it? But where would this come from?

构建本身不会引发任何错误,我认为我正确地需要 d3-tip,根据这个问题.控制台语句按预期显示 d3 版本 3.5.17.

The build itself does not throw any errors, and I think I'm requiring d3-tip correctly, as per this question. The console statement shows d3 version 3.5.17, as expected.

更新:这是我的 package.json 文件:

UPDATE: Here's my package.json file:

{ "name": "myapp", "version": "1.0.0", "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "watch": "watchify index.js -o main.js --debug --verbose", "build": "browserify index.js | uglifyjs > main.min.js" }, "dependencies": { "d3": "^3.5.17", "d3-tip": "^0.7.1", "datatables": "^1.10.12", "datatables-bs": "^1.10.12" }, "devDependencies": { "uglifyjs": "^2.4.10", "watchify": "^3.2.1" } }

我用 npm install 安装了这些文件.

And I installed the files with npm install.

推荐答案

发生这种情况是因为我试图将最新版本的 d3-tip(需要 D3 的 v4)与 D3 的 v3 一起使用.

This was happening because I was trying to use the latest version of d3-tip (which requires v4 of D3) with v3 of D3.

恢复到旧版本的两个固定的东西:

Reverting to older versions of both fixed things:

"d3": "^3.5.17", "d3-tip": "^0.6.7"

更多推荐

将 d3

本文发布于:2023-08-04 01:28:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1291684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!