Skip to content

Scaling issue with y-axis #8380

@alexkuc

Description

@alexkuc

I am having a difficulty with automatic scaling:

Screen Shot 2021-02-05 at 01 28 27

As you can see, the chart is "cutting" into the top.

Here is my config:

class BarChartFactory {
  create = (id, labels, datasets) => {
    return new Chart(document.getElementById(id).getContext("2d"), {
      type: "bar",
      data: {
        labels: labels,
        datasets: datasets,
      },
      plugins: [ChartDataLabels],
      options: {
        scales: {
          y: {
            type: "linear",
            beginAtZero: true,
            scaleLabel: {
              display: true,
              labelString: "text",
            },
          },
          y2: {
            type: "linear",
            beginAtZero: true,
            position: "right",
            scaleLabel: {
              display: true,
              labelString: "text",
            },
            gridLines: {
              drawOnChartArea: false,
            },
          },
          x: {
            type: "time",
            ticks: {
              source: "labels",
              autoSkip: false,
            },
            adapters: {
              date: {
                locale: locale,
              },
            },
          },
        },
        plugins: {
          legend: {
            position: "bottom",
          },
          datalabels: {
            backgroundColor: function (context) {
              let color = context.dataset.backgroundColor;
              color = color.replace(/[^,]+(?=\))/, "1");
              return color;
            },
            formatter: function (value, context) {
              return value + "%";
            },
            display: false,
            borderRadius: 25,
            color: "white",
            font: {
              weight: "bold",
            },
            padding: 6,
          },
        },
      },
    });
  };
}

I am using v3 (3.0.0-beta.10).

I know that I can manually supply either suggestedMax or max values to the scale.

However, I wanted to double check if chart.js offers some other setting or option which I could try?

Ps. I filled this issue as help requested instead of bug, as I am not sure whether this is a bug or a misconfiguration

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions