D3.js 更改鼠标悬停上的d3类
我正在使用D3V4并尝试将样式应用于鼠标悬停上的元素。 我想知道这是否是V4的API变化,但我似乎无法进入节点 我有密码:D3.js 更改鼠标悬停上的d3类,d3.js,mouseover,D3.js,Mouseover,我正在使用D3V4并尝试将样式应用于鼠标悬停上的元素。 我想知道这是否是V4的API变化,但我似乎无法进入节点 我有密码: .on('mouseover', () => { let self = d3.select(this); let c = self.attr('class'); 但这是一个错误 Cannot read property 'getAttribute' of null 因此,d3.select()似乎不起作用。。。 然而,鼠标器正在开火 我可以用 .on('m
.on('mouseover', () => {
let self = d3.select(this);
let c = self.attr('class');
但这是一个错误
Cannot read property 'getAttribute' of null
因此,d3.select()
似乎不起作用。。。
然而,鼠标器正在开火
我可以用
.on('mouseover', (elem) => {
console.log('elem', elem);
这将给我一些类型的D3对象,但不是DOM节点。
我不能在这个对象上使用任何D3方法
elem.classed("hilite", true);
elem.attr("class", "hilite");
这些方法都不存在于d3返回的对象上
那么我如何在d3中完成这个超基本的操作呢
有关
如果您不需要访问当前元素的
此
,则可以使用箭头函数(如果这是箭头函数)。在这种情况下,您确实需要,因为D3调用事件处理程序设置this
,以触发此事件的元素
请参阅:如果这是TypeScript,请提供它生成的JavaScript代码(或者可能是一个提琴)?d3.select应该可以正常工作:你能为此做一把小提琴吗?不需要小提琴,这只是胖箭头函数中的
this
的意思。