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

Time scale combo chart X axis labels off by one #10889

Closed
pkariz opened this issue Nov 18, 2022 · 4 comments
Closed

Time scale combo chart X axis labels off by one #10889

pkariz opened this issue Nov 18, 2022 · 4 comments

Comments

@pkariz
Copy link

pkariz commented Nov 18, 2022

Expected behavior

in the example shown in the documentation the first label on the X-axis should be Nov 18 and the last one should be Nov 24. While that holds for both bars and line if you mouse over their data, the X axis shows the next day.

Current behavior

It shows the next day, so where bars and line show Nov 18, the X axis shows Nov 19. The last label on the X-axis is not shown when it should be (and have the same value as bars/line, so Nov 24).

Reproducible sample

https://www.chartjs.org/docs/latest/samples/scales/time-combo.html

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.0.1

Browser name and version

No response

Link to your project

No response

@kurkle
Copy link
Member

kurkle commented Nov 19, 2022

The scale ticks are at midnight while the data has current time in it. So it depends on the time of day. Maybe the Utils.newDate should set time to midnight?

@pkariz
Copy link
Author

pkariz commented Nov 19, 2022

i've tried setting the time to 00:00:00 and what i get is the correct labels except the first label is now missing instead of the last one. So 19. nov data is there but there is no 19. Nov label, 20. nov data is there and label is correctly set to 20. Nov.

Just to elaborate more on what i'm trying to achieve. I have data A, B and C, where each of them is the amount of A/B/C per specific day and B and C are similar in a way that they're like "competitors", so i want to show A as a line, B and C as bars. All of course showing data on specific day

@vanHekthor
Copy link

vanHekthor commented Dec 18, 2022

@pkariz I agree that the way it is right now is quite confusing as it looks wrong at first (https://www.chartjs.org/docs/latest/samples/scales/time-combo.html)

image

Only after a quite a while I realized that 00:00:00 of each day is in the center between the grid lines.
Moreover, in the other time scale example the date labels are positioned differently (00:00:00 where the vertical grid lines are):

image

Maybe the config could be changed slightly?

2 ideas come into my mind:

Idea 1

Basically doing what kurkle suggested and adding:

...
scales: {
  x: {
    ...
    time: {
      ...
      round: 'day',
    },        
  },
},
...

image

Idea 2

Moving the 00:00:00 of each day to the position of the vertical grid lines:

...
scales: {
  x: {
    ...
    grid: {
      offset: false,
    }
  },
},
...

image

@kurkle If appreciated, I can do a PR with the preferred option.

@mukham12
Copy link
Contributor

Greetings,

Is this issue not similar to the recently resolved matter documented in issue #11229, accompanied by pull request #11284? Both issues revolve around the problematic exhibition of tooltips caused by the misalignment of bar stacks within their respective ticks in the bar chart. Considering the correlation between the two cases, is it a good idea to close this issue, given that the proposed pull request has been successfully merged?

Many thanks.

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

No branches or pull requests

5 participants