Javascript 如何从react vis中的onValueMouseOver获取事件?
根据,Javascript 如何从react vis中的onValueMouseOver获取事件?,javascript,reactjs,charts,react-vis,Javascript,Reactjs,Charts,React Vis,根据,onValueMouseOver应返回事件和数据点。然而,这一事件似乎没有通过。我做错什么了吗 const Charts = () => { const data = [ { x: 1, y: 1 }, { x: 2, y: 1 }, { x: 3, y: 5 }, { x: 4, y: 5 }, { x: 5, y: 1 }, ]; return ( <XYPlot height={400} width={400}
onValueMouseOver
应返回事件
和数据点
。然而,这一事件似乎没有通过。我做错什么了吗
const Charts = () => {
const data = [
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 5 },
{ x: 4, y: 5 },
{ x: 5, y: 1 },
];
return (
<XYPlot height={400} width={400}>
<VerticalBarSeries
data={data}
onValueMouseOver={(datapoint, event) => {
console.log(event.target); // undefined
}}
/>
</XYPlot>
);
};
const Charts=()=>{
常数数据=[
{x:1,y:1},
{x:2,y:1},
{x:3,y:5},
{x:4,y:5},
{x:5,y:1},
];
返回(
{
console.log(event.target);//未定义
}}
/>
);
};
实际上,事件
参数有一个事件
属性,您可以使用和访问实际事件
你可以这样做:
{
console.log(event.event.target);//一些SVG元素
}}
/>
或者使用解构:
{
console.log(event.target);//一些SVG元素
}}
/>