Ajith Rock
Ajith Rock

Reputation: 90

react-chartjs-2 bar touches the top

When the data is filled it hits the top of the line. is there any option to limit the top, and I need the show the number with money symbol.

I need to change the x-axis to show more than the top limit. is there any option to it

reac

          <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;
                      },
                    },
                  },
                ],
              },
            }}
          />

Upvotes: 0

Views: 1319

Answers (1)

William Scalabre
William Scalabre

Reputation: 653

I think you could try something like in the example i made here: https://stackblitz.com/edit/react-boilerplate-scalabw-45793890

You can use the max in the scales: { yAxes : [{max: maxvalue}] }

You just need to add a function which get the maximum value and add the "padding value".

i also simplified you code in my example because you got a repetition between yAxes and yAxes.

Upvotes: 3

Related Questions