Get getMinMax from a scale #11250
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
@stockiNail any idea on how I can achieve this? thanks 🙏 |
Beta Was this translation helpful? Give feedback.
-
@ronildo as far as I understood, you are trying to access to the controller to get min and max. Let me assume you are using the To be compliant with Chart.js code and visibility of the methods, you could extend the existing line controller adding a public method which is invoking the Here I'm creating my LINE controller ( // Controller
class MyLineController extends Chart.LineController {
getMaxMin(scale, canStack) {
return super.getMinMax(scale, canStack);
}
};
MyLineController.id = 'myLine';
MyLineController.defaults = Chart.LineController.defaults;
Chart.register(MyLineController); Note that I have changed the name of the method in In your chart you can set the chart type to 'myLine' as following: // Chart
const config = {
type: 'myline',
data: {
...... Then you code could be: const visibleMetas = chart.getSortedVisibleDatasetMetas();
const minMaxScale = visibleMetas.map(meta => ({
...meta.controller.getMaxMin(chart.scales.y, true) // <--- new method of your controller
})); See codepen: https://codepen.io/stockinail/pen/PoyOqNY You could do the same at scale level (creating your scale extension) but I think it could be more complex, if I have understood well your use case. |
Beta Was this translation helpful? Give feedback.
@ronildo as far as I understood, you are trying to access to the controller to get min and max. Let me assume you are using the
line
controller (but it could be the same for bar or others).To be compliant with Chart.js code and visibility of the methods, you could extend the existing line controller adding a public method which is invoking the
getMinMax
one.Here I'm creating my LINE controller (
vanillaJS
but it's the same with other framework but you need to import the controller and removeChart
namespace).