d3获取d3.event.tranform为null

在webpack项目中,使用d3.event.transform获取位置信息时,结果返回为空。为了解决这个问题,可以使用如下方式:

import * as d3 from "d3";
import { event as currenEvent } from "d3-selection";

const transform = currenEvent.transform;

引入d3-selection中的event即可解决该问题。

在之前的文章中也有相关介绍:{% post_link cannot-read-property-button-of-null-in-d3 %}

如果您觉得本文对您有用,欢迎捐赠或留言~
微信支付
支付宝

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注