vendredi 17 avril 2020

Move highcharts yAxis.tickPositioner callback function outside to some util function

I'm trying to implement highcharts with multiple y-axis and need to set yAxis.tickPositioner callback function for each of the y-axis. So instead of writing the duplicate code in each callback I need to create a util function to which I can pass values like dataMin and dataMax which is only accessible in the tickPositioner callback function.

chartOptions {
    xAxis: {
        tickPositions: [0, 1, 2, 4, 8]
    },

    yAxis: {
        tickPositioner: function () {
            var positions = [],
                tick = Math.floor(this.dataMin),
                increment = Math.ceil((this.dataMax - this.dataMin) / 6);

            if (this.dataMax !== null && this.dataMin !== null) {
                for (tick; tick - increment <= this.dataMax; tick += increment) {
                    positions.push(tick);
                }
            }
            return positions;
        }
    },
}

instead I want something like this which has all the values like this.dataMin and this.dataMax available in the util function

    chartOptions {
        xAxis: {
            tickPositions: [0, 1, 2, 4, 8]
        },

        yAxis: {
            tickPositioner: this.utilFunction();
        },
    }

utilFunction() {
            var positions = [],
                tick = Math.floor(this.dataMin),
                increment = Math.ceil((this.dataMax - this.dataMin) / 6);

            if (this.dataMax !== null && this.dataMin !== null) {
                for (tick; tick - increment <= this.dataMax; tick += increment) {
                    positions.push(tick);
                }
            }
            return positions;
        }



Aucun commentaire:

Enregistrer un commentaire