Chart.js
Chart.js copied to clipboard
Remove default axis overrride when custom ID is given.
Feature Proposal
Remove the default scale override for x/y axis if a different axis id is given.
In case you want to add a second x axis you need to add an empty x scale object which is weird. Also when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale but as soon as you specify the place it replaces the current default x/y scale
Possible Implementation
No response
Also when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale but as soon as you specify the place it replaces the current default x/y scale
@LeeLenaleee maybe I'm wrong, but instead of specifying the position (as you have done here https://jsfiddle.net/Leelenaleee/3b27jqah/6/), you could set axis
option, axis: 'x'
and then you can use whatever ID you want.
No I think you might understand it wrong, tried to explain it a bit better underneath here
Like the example you linked I want to add a second X axis, im totally fine with the original so don't need any config for that. So I add a scale config for axis x2
. This would for my feeling create a second x axis or at least a new axis. But instead it overrides the default x scale.
scales: {
x2: {} // overrides default x so still only 2 scales, 1 x and 1 y scales
}
If I instead make a scale (without any config) with an id that chart.js can not infer the type from like secondX
it will create an extra scale and make it a y scale. So I have 2 y scales and 1 x scale. But as soon as I specify the axis
field or position
field it overrides the default y/x axis again.
scales: {
secondX: {} // create extra y scale, 1 x and 2 y scales
}
scales: {
secondX: { // overrides default x so still only 2 scales, 1 x and 1 y scales
position: 'bottom', // Both the position and axis prop independintly make it override default scale
axis: 'x'
}
}
So only way to create a custom new scale (as far as my knowledge goes) is by adding an empty scale object for the default x/y scale which feels verry weird. Especially since if you make a scale ID chart.js cant infer without config to test if it renders it does render but then as soon as you add condig it stops rendering and makes it the default scale.
scales: {
x: {}, // Feels weird and wrong that this needs to be done
x2: {
// All config
}
}
@LeeLenaleee sorry I misunderstood that and now it's clear! I didn't recognize that the second axis will override the default one and you are definitely right. I had the doubt about the usage of position
instead of axis
option.
@LeeLenaleee I was thinking about this issue. Maybe you should remove the default scale override because I have seen many users which are using CHART.JS, assuming that this is the behavior. Nevertheless I agree with you that it's annoying to add an "empty" scale definition, only to maintain the default one.
Maybe new option could be added to the cartesian scales (for instance override
or overrideDefault
) where the user can specify that the new scales are on top to the default one.
override?: boolean // default `true`, as is today. In this way it could not be a breaking change
when adding a custom scale that chart.js does not know the kind of (because of first letter) it does appear as an extra y scale
This one is a bug, it should override the default y-scale in that case (per current design).
@LeeLenaleee @stockiNail @kurkle Hi guys. Could you please finalize the decision about this issue?
- should we disable override at all?
- do it by
override
option? - ...
@LeeLenaleee @stockiNail @kurkle ping
My preference goes to removing it so any scale ID except for x
/y
creates a second scale next to the main one.
@etimberg what is your opinion on this?
If I understand correctly @LeeLenaleee this would create two x and two y axes:
const options = {
scales: {
x2: { type: 'category' },
y2: { type: 'linear; },
}
}
I think that could make sense. my one concern is that it makes upgrades harder to do because if someone set an ID before it will change and there's no way to have the case above make 2 axes because you can't delete x
and y
yes your config would indeed make 2 x and 2 y axes with the proposed change.
So if we do this I think we need to make it verry clear at the top of the migration guide.
I encountered an example chart that was affected by this: v3 https://codepen.io/kurkle/pen/gOzzPvE v4 https://codepen.io/kurkle/pen/ExxdyXQ
Now you'd need to display: false
on the unused default scales. Maybe we should at least change the display default to 'auto'
?