Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping labels on x axis #6109

Closed
listefano opened this issue Mar 5, 2019 · 6 comments · Fixed by #6115
Closed

Overlapping labels on x axis #6109

listefano opened this issue Mar 5, 2019 · 6 comments · Fixed by #6115
Milestone

Comments

@listefano
Copy link

Expected Behavior

Labels should be skipped or rotate so they are not overlapping.

Current Behavior

If the browser gets resized the labels on the x axis could get overlapped.
chart

Steps to Reproduce (for bugs)

  1. Create a line chart with a x axis of type "time" and no data.
  2. Resize the browser so the chart gets smaller/bigger.

Here is a sample of the problem:
https://codesandbox.io/s/1vm83xknoj?fontsize=14

Context

I get the data from an custom private API and want to visualize the data with chart.js.

Environment

  • Chart.js version: 2.7.3
  • Browser name and version: Google Chrome v72.0.3626.119 | CefSharp V69
@benmccann
Copy link
Contributor

benmccann commented Mar 5, 2019

@kurkle
Copy link
Member

kurkle commented Mar 6, 2019

Seems like a bug to me. The fewer the labels, the more they overlap before rotated or skipped. So could be a +-1 thing.

@listefano
Copy link
Author

It seems that the setting of autoSkip to true already fixes my problem. Maybe a note in the docs for the autoSkip setting for the time scale would be helpful.

Thanks for the quick reply

@benmccann
Copy link
Contributor

@kurkle raised a good point though that there is a bug here because this shouldn't happen even without autoSkip enabled

@mrleblanc101
Copy link

How do I prevent this ?
I tried the autoSkip option, but it would skip over the "June" month label instead of "May"
Screenshot 2024-07-07 at 11 05 21 PM

@ntbosscher
Copy link

The overlap still seems to be an issue on time series with v4.4.4
@simonbrunel can we reopen or should I file a new issue?

image

Config

const config = {
  type: 'line',
  data,
  options: {
    scales: {
      x: {
        type: "time",
        time: {
          displayFormats: {
            hour: "dd-M-yyyy HH:mm:ss a",
          },
          unit: "hour"
        },
        border: {
          color: 'red'
        },
        ticks: {
           maxRotation: 0,
           autoSkip: true,
           align: "inner",
         }
      }
    }
  }
};

Setup

const labels = [0, 1, 2, 3, 4, 5, 6, 7].map((i) => Date.now() + 60 * 60 * 1000 * i);
const data = {
  labels: labels,
  datasets: [{
    label: 'My First dataset',
    backgroundColor: 'rgba(54, 162, 235, 0.5)',
    borderColor: 'rgb(54, 162, 235)',
    borderWidth: 1,
    data: [10, 20, 30, 40, 50, 0, 5],
  }]
};

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants