【问题标题】:react native chart kit responsive is not working反应本机图表套件响应不起作用
【发布时间】:2021-04-20 16:42:37
【问题描述】:

我试图让 react native 的图表响应,根据那里的文档,如果你想响应图表,你必须放在下面的代码中。我检查了其他代码,但他们的代码正在运行。试了好久还是解决不了

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....

【问题讨论】:

  • 你遇到了什么错误?
  • 没有错误...这不是响应...

标签: react-native charts react-native-chart-kit


【解决方案1】:

尝试使用 useWindowDimensions

import { useWindowDimensions } from 'react-native';

const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多