簡體   English   中英

react-chartjs-2 bar 觸頂

[英]react-chartjs-2 bar touches the top

當數據被填充時,它會到達行的頂部。 有沒有限制頂部的選項,我需要用錢符號顯示數字。

我需要更改 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;
                      },
                    },
                  },
                ],
              },
            }}
          />

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

您可以在scales: { yAxes: [{max: maxvalue}] }

您只需要添加一個 function 即可獲得最大值並添加“填充值”。

我還在我的示例中簡化了您的代碼,因為您在 yAxes 和 yAxes 之間有重復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM