Yaxis Values on High Chart Customization

2019-07-25 10:45发布

问题:

I have been trying to populate yaxis values on my highchart as per defined by me and results should be shown accordingly but all my efforts are in vain i am not able to manually set this.value of yaxis of highchart . Following is a link to my Jsfiddle . Kindly help..

http://jsfiddle.net/CzHyC/12/

In the following JS COde I have been trying to set the this.value of yaxis to the arrayed values of yAxisLabels but values are not being labled and chart is not dislayed accordingly.

JS CODE FOR YAXIS

var yAxisLabels = ['5','10','20','30','40','50'];


yAxis: {
    labels: {
        formatter: function () {
            for (i=0; i<=5; i++) {
                this.value=yAxisLabels[i];
                return this.value;
            }
        }
    },

    title: {
        text: 'Total fruit consumption'
    },
    stackLabels: {
        enabled: true,
        style: {
            fontWeight: 'bold',
            color: (Highcharts.theme && Highcharts.theme.textColor) || 'blue'
        }
    }
}

回答1:

You can use the Tick Positioner to define your axis tick values:

See jsfiddle

The important parts are:

var yAxisLabels = [0, 5, 10, 20, 30, 40, 50];

your axis label array containing numbers and not strings

and

tickPositioner: function() {
                return yAxisLabels;
            },

the tickPositioner returning your array.

TickPositioner Documentation



回答2:

you can also set like this

tickPositions: [0, 5, 10, 20, 30, 40, 50],