0

我试图使反应本机的图表响应,根据那里的文档,如果你想响应图表,你必须把它放在代码下面。我检查了其他代码,但他们的代码正在运行。我尝试了很多但我无法解决它

import { Dimensions } from "react-native";
const screenWidth = Dimensions.get("window").width;

<LineChart
  data={data}
  width={screenWidth}
  height={220}
  chartConfig={chartConfig}
/>

但我尝试过像这样

const screenWidth = Dimensions.get("window").width;

<LineChart
          data={{
            labels: ["January", "February", "March", "April", "May", "June"],
            datasets: [
              {
                data: [
                  Math.random() * 100,
                  Math.random() * 100,
                  Math.random() * 100,
                  Math.random() * 100,
                  Math.random() * 100,
                  Math.random() * 100,
                ],
              },
            ],
          }}
          width={screenWidth} // from react-native
          height={220}
        />
    ```

Can anyone help me why it is not working....

4

1 回答 1

0

尝试使用 useWindowDimensions

import { useWindowDimensions } from 'react-native';

const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;
于 2021-06-16T00:33:52.270 回答