【问题标题】:react-native-chart-kit barchart graph cuttingreact-native-chart-kit 条形图图形切割
【发布时间】:2021-02-16 12:12:37
【问题描述】:

我是react-native-chart-kit 的 barchar 我想在图表中显示月份数据,但是当我在图表中设置数据时,它正在削减。看我分享的图片&代码

const data = {
  labels: [
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec',
  ],
  datasets: [
    {
      data: [
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
        Math.random() * 100,
      ],
      color: (opacity = 1) => `rgba(192, 112, 47, ${opacity})`,
    },
  ],
};

<BarChart
              width={width}
              height={height}
              data={data}
              yLabelsOffset={25}

              chartConfig={{
                backgroundColor: colors.blank,
                backgroundGradientFrom: colors.blank,
                backgroundGradientTo: colors.blank,
                color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
                decimalPlaces: 0,
                style: {
                  fontFamily: env.fontRegular,
                },
                propsForLabels: {
                  fontFamily: env.fontRegular
                },
              }}
              style={{
                marginVertical: 8,
                borderRadius: 16,
              }}
            />

【问题讨论】:

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


    【解决方案1】:

    一个可能的解决方案是在chartConfig 上将barPercentage 设置为小于1 的值。这将使条形更小,同时仍将它们分布在可用空间中。

        <BarChart
          width={windowWidth}
          height={300}
          data={data}
          yLabelsOffset={25}
          chartConfig={{
            color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
            decimalPlaces: 0,
            style: {},
            propsForLabels: {},
            barPercentage: .3
          }}
          style={{
            marginVertical: 8,
            borderRadius: 16,
          }}
        />
    

    【讨论】:

    • 它可以工作,但条形宽度很小。有没有办法在开始时减少 Ylabels 和 bar 之间的左侧空间?
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    相关资源
    最近更新 更多