Closed misaki-web closed 1 year ago
Reopening to enable the multi axis logic to be made active in the block editor.
yAxes
.y
or y1
y
In the editor code each object in datasets
needs to have the yAxisID
attribute set to "y"
or "y1"
.
Also when multiple axes are required options.scales.y1
needs to be set similar to scales.y
but with "position":"right"
eg
"y1":{"beginAtZero":true,"position":"right","stacked":false}}};
Here's a screenshot of the front-end for 4 charts with identical values but different setttings for the y-axes.
Here's a screenshot of the block editor for the same 4 charts.
Notes:
y1
( 30, 40, 50 )The x-axis font size is not being applied on the front end.
That's because we haven't completed #21
Note: If you deselect all the lines that are used for a particular y-axis the scales are reset. This is standard chart.js behaviour that probably isn't easy to change.
When there are more than 2 lines the result of deselection is quite interesting.
The block editor should support charts where the yAxes
attribute is not set.
It currently produces an error Cannot read properties of undefined (reading 'includes')
at
if ( this.attributes.yAxes.includes( 'y1' ) ) {
Deliveredin v1.2.0
Here's an example of multi axis line chart in the Chart.js documentation:
Scales settings must have
y
andy1
, and each dataset must be linked to a specific axis. Here's a very quick and dirty way just to get an idea of what's needed:The shortcode to test:
The result: