[charts] Plotting multiple axes for a single series
Steps to reproduce
Steps:
- Open this link to live example: https://codesandbox.io/embed/nzdhp6?module=/src/Demo.js&fontsize=12
- Replace
xAxisby this
xAxis={[
{
id: 'color',
min: 0,
max: 100,
valueFormatter: (value) => `${value}%`,
position: 'bottom'
},
{
id: 'notick',
min: 0,
// max: 100,
valueFormatter: (value) => `${value}%`,
position: 'top'
},
]}
- No ticks on the top axis. Uncomment
max: 100, and it works.
Current behavior
The ticks are not working on the second xAxis if there is no max value, whatever the position. But it works for the first axis.
Expected behavior
It should work the same whatever the number of axes we have.
Context
Horizontal bar charts.
Your environment
Check codesandbox
Search keywords: tick ticks axis xaxis
Ticks are values going from the min to the max. This axis does not know which max value to use, so it can not render ticks.
There are two ways for an axis to get min/max value:
- You explicitly provide it (like we do with
min: 0, max:100) - They get derived from the series using it. For example if you remove the
max: 100of the first axis, it will notice that the series max value is88.5which will round at90
Do you want to display the same axis two times? If that's the case, I'm not sure we support this option
Hey, @flomillot.
This is expected behavior.
The first x-axis works because if a series doesn't identify its axis explicitly, we will default to the first axis.
The second x-axis isn't referenced by any series, so it isn't possible to know its domain. You can specify the domain by providing min and max, or by creating a series that references this axis using the xAxisId property.
Could you explain your use case? That would help us guide you how to get to your desired implementation.
The thing is it was working on the previous version (V7).
Check here : https://codesandbox.io/embed/dwvyvy?module=/src/Demo.tsx&fontsize=12 Replace this part :
const chartSetting = {
bottomAxis:
{
id: 'color',
position: 'top'
},
topAxis: {
id: 'notick',
position: 'bottom'
},
width: 500,
height: 400,
};
We didn't need to set a min or max value.
I though it was a regression, but if it's expected, no worries, I will use min and max values. Your explanations make sense with the new API.
PS : what we did
Thank you for your quick answer.
You will notice this breaking change came with an improvement. you don't need to modify the margin to leave space for axes. But that came with a cost: You need to defines where the axis will appear directly in the axis configuration
We could add a position: 'both' to allow displaying the same axis on top & bottom (or left & right for y-axis)
From the screen shot, it looks like you do not render exactly the same stuff on the two axes. Could you explain your usecase. It would be usefull for us to improve our API since it's probably a usecase we ignore
By the way, glad to see the lib used in some RTE projects :)
Sorry I just do the MUI X migration and haven't work on it before, but it's probably a 'weird' or unconventional usecase and we found that MUI X Charts was the more suitable for it. Thank you for your work on all MUI libs, it's very helpful for us ! (I'm external so talking for myself)