【问题标题】:react-chartjs-2 bar touches the topreact-chartjs-2 bar 触顶
【发布时间】:2020-04-29 17:49:44
【问题描述】:

当数据被填充时,它会到达行的顶部。有没有限制顶部的选项,我需要显示带有货币符号的数字。

我需要更改 x 轴以显示超过上限。有什么选择吗

          <Bar
            data={incomePropertyData}
            width={100}
            height={450}
            options={{
              maintainAspectRatio: false,
              legend: {
                display: true,
                fontColor: "#686868",
                fontFamily: "kanit, sans-serif",
              },
              tooltips: {
                titleAlign: "center",
                titleMarginBottom: 8,
                bodyFontFamily: "'Nunito', sans-serif",
                callbacks: {
                  label: function (tooltipItem, data) {
                    var label =
                      data.datasets[tooltipItem.datasetIndex].label || "";
                    if (label) {
                      label += " : ";
                    }
                    label += "₹ " + tooltipItem.yLabel;
                    return label;
                  },
                },
              },
              responsive: true,
              scales: {
                yAxes: [
                  {
                    ticks: {
                      fontFamily: "'Nunito', sans-serif",
                      fontSize: 14,
                    },
                  },
                ],
                yAxes: [
                  {
                    ticks: {
                      fontFamily: "'Nunito', sans-serif",
                      fontSize: 14,
                      beginAtZero: true,
                      callback: function (value, index, values) {
                        return "₹ " + value;
                      },
                    },
                  },
                ],
              },
            }}
          />

【问题讨论】:

  • 你能发布一些代码
  • 这是代码 sn-p。

标签: reactjs chart.js react-chartjs chartjs-2.6.0


【解决方案1】:

我想你可以试试我在这里做的例子: https://stackblitz.com/edit/react-boilerplate-scalabw-45793890

你可以在scales: { yAxes : [{max: maxvalue}] }中使用最大值

您只需要添加一个获取最大值的函数并添加“填充值”。

我还在示例中简化了您的代码,因为您在 yAxes 和 yAxes 之间有重复。

【讨论】:

  • 成功了。有没有其他方法可以用步数设置最大值? y 轴也算奇数。每一步我得到 500 .. 是否有可能获得步数,所以我可以添加一个额外的步骤。所以看起来不错
  • 我修改了上面链接中的选项,如果您想要的话,请告诉我。您可以使用秤:{ yAxes : [{stepSize: stepSizeValue}] }
  • 你应该验证这个答案,因为它符合你的要求;)
  • @WilliamScalabre 链接未使用步长更新。请问可以更新吗?非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
  • 1970-01-01
  • 2022-11-02
  • 2022-12-31
  • 1970-01-01
  • 2023-01-27
相关资源
最近更新 更多