环境d3 v7
react 18.0
import * as d3 from 'd3';
.on("mouseover",function(e){
d3.select(this).attr("fill","#f34848")
console.log(g.node(parseInt(e.toElement.__data__)).description)
tooltip.html(g.node(parseInt(e.toElement.__data__)).description)
.style('left',(d3.event.pagex)+'px')
.style('top',(d3.event.pagey)+'px')
.style('opacity',1.0)
})
报错
export ‘event’ (imported as ‘d3’) was not found in ‘d3’
原因:
事件是function(e) 中e,不是d3.event
import * as d3 from 'd3';
.on("mouseover",function(e){
d3.select(this).attr("fill","#f34848")
console.log(g.node(parseInt(e.toElement.__data__)).description)
tooltip.html(g.node(parseInt(e.toElement.__data__)).description)
.style('left',(e.pagex)+'px')
.style('top',(e.pagey)+'px')
.style('opacity',1.0)
})