When zooming on a line/area chart, it would be cool to automatically change the y-axis scale
Try options.chart.zoom.type: 'xy' to allow zooming on both axes.
Docs- https://apexcharts.com/docs/options/chart/zoom/#type
Hi, by searching in source code, I found the brush function.
It could be cool implement an 'autoZoomY' option in chart.brush
I wrote it just here :
w.config.chart.events.selection = function (chart, e) {
let yaxis = {}
if (w.config.chart.brush.autoZoomY) {
let min, max;
min = max = 0;
targetChart.w.config.series.forEach(serie => {
if (serie[1] > max) max = serie[1];
if (serie[1] < min) min = serie[1];
});
yaxis = {min, max};
}
targetChart._updateOptions({
xaxis: {
min: e.xaxis.min,
max: e.xaxis.max
},
yaxis: {
min: yaxis.min*0.95,
max: yaxis.max*1.05
}
}, false, false);
};
correspond to the line 846 of src/modules/Core.js
Hi @AurelReb firstly this library is awesome!
I was wondering if it would be possible to add an option, so to auto scale the y axis of a time series on zoom.
In this example https://codepen.io/T-Pullen/pen/wZpJJg I have an outlier that ruins the the y axis for all other points. I would be prefect if the y axis would auto scale to the y axis values within the zoomed selection.
Alternatively, would it be possible to implement a possitiveOnly option for the zoom options.chart.zoom.type: 'xy'. Which would prevent the user selecting an area on the negative side of the Y/X axis.
Hey, Thank you for the implementation of this feature!
I have a question about the autoScaleYaxis prop which appears to don't do anything, see the following example:
https://codesandbox.io/embed/react-brush-example-6ijx5
You can see that the first data are not showing and that zooming with the brush or with the cursor has no effect.
Am I wrong on the chart's options?
The issue will be fixed in 3.8.0
The last publish didn't include the updated code.
Feel free to re-open if the new version doesn't fix it.
Thank you very much, it works perfectly!
Most helpful comment
Try
options.chart.zoom.type: 'xy'to allow zooming on both axes.Docs- https://apexcharts.com/docs/options/chart/zoom/#type