reactjs 如何在Victoy区域中获得按下的y轴值

dluptydi  于 2023-03-01  发布在  React
关注(0)|答案(1)|浏览(116)

你好啊
从上面的图像,如果我触摸一个区域,我应该从胜利区得到y轴值。
我在VictoryArea组件events={[{ target: 'data', eventHandlers: { onPressIn: (props) => { console.log(props); } } }]}上尝试将其作为 prop
我在 prop 里面找不到

cngwdvgl

cngwdvgl1#

要在React Native中获取Victory区域图中按下的y轴值,可以使用Victory提供的onPress事件处理程序。

import React, { useState } from "react";
import { VictoryArea } from "victory-native";

const Chart = () => {
  const [yValue, setYValue] = useState(null);

  const handlePress = (event, props) => {
    const { y } = props.datum;
    setYValue(y);
  };

  return (
    <>
      <VictoryArea
        data={[
          { x: 1, y: 2 },
          { x: 2, y: 3 },
          { x: 3, y: 5 },
          { x: 4, y: 4 },
          { x: 5, y: 7 },
        ]}
        onPress={handlePress}
      />
      {yValue && <Text>Y value on press: {yValue}</Text>}
    </>
  );
};

export default Chart;

相关问题