Set second axis in proportion of first axis

2019-08-09 02:32发布

问题:

I have a chart which contains two series, and each of them has its own yAxis. I need to automatically set the second axis maximum to 13.5% of the first axis maximum. For example, if the first axis goes from 0 to 100, then I want the second axis to go from 0 to 13.5 (No matter the second series value).

The only way I found to achieve this is to calculate the max of the first series, and then affect it to the max of the second axis. But this is not what I really want. See this JSFiddle.

My fiddle seems to work, but in reality, I am not calculating the second axis maximum in a good way, as I refer to the first series maximum and not the first axis maximum.

Does anyone knows a general way to set the max of an axis accordingly to the max of another axis ?

The linkedTo attribute from Highcharts axis is close to what I want, but I need to add a coefficient. I don't know how to proceed.

回答1:

There is no default API function in Highcharts that would allow that.

If you want to get percentage of max of created axis, then you can get it in load event of chart (API: http://api.highcharts.com/highcharts#chart.events.load )or in callback (as in demo below). Next you will need to update second axis' max.

Example: http://jsfiddle.net/cg0c5tkd/

function(chart){
        chart.yAxis[1].update({max: chart.yAxis[0].getExtremes().max * 0.135});
    }