[Chartjs]-How to Create a Custom Logarithmic Axis in Chart.js

4👍

I fixed it.

Modify the yAxes callback as shown:

                    yAxes: [{
                    type: 'logarithmic',
                    ticks: {
                        autoSkip: true,
                        min: 0,
                        callback: function (value, index, values) {
                            if( value==10 || value==100 || value==1000 || value==10000 || value==100000  || value==1000000){
                                return value + ' years';
                            }
                        }
                    },
                    scaleLabel: {
                        display: true,
                        labelString: 'Mean Time Between Stock-Out'
                    }
                }]

Then you only return a tick if the value is a power of ten.

Leave a comment