按第一轴的比例设置第二轴 [英] Set second axis in proportion of first axis
问题描述
我有一个包含两个系列的图表,每个图表都有自己的 yAxis
。我需要自动将第二轴的最大值设置为第一轴最大值的13.5%。例如,如果第一个轴从0到100,那么我希望第二个轴从0到13.5(无论第二个系列值)。
我发现实现这一点的唯一方法是计算第一个系列的最大值,然后将其影响到第二个轴的最大值。但这不是我真正想要的。 看到这个JSFiddle。
我的小提琴似乎工作,但实际上,我并没有很好地计算第二轴最大值,因为我指的是第一个系列最大值而不是第一个轴最大值。 / p> 有没有人知道将轴的最大值设置为另一个轴的最大值的一般方法?
linkedTo
属性接近我想要的,但我需要添加一个系数。我不知道如何继续。
如果您想获得创建轴的最大百分比,那么您可以在图表的加载事件中获取它(API: http://api.highcharts.com/highcharts#chart.events.load )或回调(如下面的演示)。接下来,您需要更新第二轴'max。
示例: http://jsfiddle.net/cg0c5tkd/
函数(图表){
chart.yAxis [1] .update({max:chart.yAxis [0] .getExtremes().max * 0.135});
}
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.
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});
}
这篇关于按第一轴的比例设置第二轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!