-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BUG] Ticks should align when multiple Y axis for line and bar chart #3484
Comments
maxTicksLimit + suggestedMax |
@frlinw has a good answer. CC @chartjs/maintainers should we provide a way of syncing number of ticks between parallel axes? |
thanks for comment. |
You can disable gridLines for the right y axis... It's not the best solution but it's probably the only one (I did that for my charts) |
I too agree with @frlinw , as it's just there for the ease in the interpretation. Anyway is this issue resolved? |
It is not yet resolved, my charts suffer from this as well. Due to their dynamic nature, I can only use "maxTicksLimit" what does not work. |
Same here, would appreciate it if someone could show me the way. |
Same problem here 2 scale misaligned, i'm using horizontalBar with 2 Y-axes with type:category so no use for suggestedMax |
Any news about this issue? the solution proposed by @frlinw only works if the two datasets have the same order of magnitude or the same measure. |
@pierfreeman Now, I agree, a perfect matching between y-axis with perfect scales is a must have. |
Hi everyone. Did anyone ever find a solution for this bug. If there is any other work around please help! |
@mikeantkowiak I'm looking for an answer to this as well. Any luck? Just hiding the gridlines for the second axis isn't really an option. Using maxTicksLimit and suggestedLimit doesn't work either |
I had to do the following to get my labels aligned: It seemed to solve the problem |
I did it like this:
|
Found a fix for this that I can't find posed anywhere not sure what version it works on.
|
Is there any news about this? Calculating the ticks can be tricky. It would be great to let Chart.js make sure the amount of ticks of all axes are always identical. |
My solution was to let ChartJS do the calculations for the ticks, but keep getting it to recalculate it until both axes have the same number of ticks by forcing them to use the minimum number of ticks for either axis for both of them as the max.
It would be really nice to have this functionality inbuilt in ChartJS to save having to loop through this ourselves. Having access to the tick calculation through an API would be could be another way to solve this and would save having to redraw the chart multiple times. |
If anyone needs to do this without forcing the scales to start from 0, I did it like this:
|
It would be really nice to be able to keep the logic of getting good numbers and just getting the ticks to align, not just setting a fixed number of ticks and forcing the labels to be random numbers to work. So I think this issue should remain open as the current merge fix doesn't solve the specific issue |
@ramykl I don't think we generate random numbers in any case. For your specific use case, please open a new issue with interactive reproduce if you want someone to take a look at it. |
What I just did that seems to work is to determine the maximum y-axis value across all your data displayed. I then set the maximum value for each of the y-axis to that value but rounded up to a round x00000 number to avoid a silly looking maximum number on the axis. This just worked. I was pleasantly surprised i didnt have to write complex code. So my graph is comprised of a 4 stacked bars and 3 not-stacked lines; 2 Y-Axis I first set the max value to 0: Then in the code that generates the datasets (1 per dataset) I had a line similar to this: Once all the dataset variables were calculated I also had a yAxisMax value that matched my highest value from all the datasets. In my case i rounded this value up to the next 5000; you can set it to anything that works for you. I just found this looked best in my case. yAxisMax = Math.ceil(yAxisMax/5000)*5000 Then in the scales configuration:
Simple. Let me know if this works for you. EDIT:
yAxisMax = Math.ceil(yAxisMax/step)*step + step |
@ChefCodev I did the opposite way and used the # of steps for each axis and kept getting the chart to keep redrawing until the # of steps were the same for both axes with a min of 3 steps |
It's 2024 and we still can't align ticks if we have multiple y-axis |
@stockiNail hardcoding the tick count creates offbeat labels depending on your dataset |
Hi there. Does anyone has a working solution for this problem. My own solution stopped working with V3.x. Thx in advance. |
anyone able to fig out the solution ? |
See https://jsfiddle.net/kng1d49d/
When I use two Y axis for line and bar in the same time, Y ticks does not align and show extra grid lines.
Expected Behavior
Y ticks should align.
Current Behavior
Y ticks does not align and show extra grid lines.
Possible Solution
In this sample, it show only one Y-axis grid line. See https://jsfiddle.net/kng1d49d/1/
But the ticks on right side still can't align, looks not good. The problem is caused by different count of ticks. Count of ticks on left side is 6, right is 5. I think to make sure rendering in the same count can fix this.
Environment
The text was updated successfully, but these errors were encountered: