[英]Highcharts - toggle auto scale
I'm trying to make a toggle button where you can freeze the scale. 我正在尝试制作一个切换按钮,您可以在其中冻结比例。 If you click again the scale is recomputed automaticlly (which is default in highcharts).
如果再次单击,则会自动重新计算比例(在highcharts中是默认值)。
Accoridng to the API reference, if y-axis = {max:null}
then the scale is automatic. 按照API参考,如果
y-axis = {max:null}
则比例是自动的。 But if I lock the scale I must extract the y-axis scale somehow so I can manually set the y-axis to the current value. 但是如果我锁定刻度,我必须以某种方式提取y轴刻度,这样我就可以手动将y轴设置为当前值。 And when I toggle back the y-axis is set to null.
当我切换回来时,y轴设置为null。
Is there anyway to extract the y-axis scale when it is set to null? 无论如何,当它设置为null时,是否提取y轴刻度? I haven't been able to find any in API.
我无法在API中找到任何内容。
Here is my highchart object 这是我的高图对象
chartFactory.getBarChart = function(data, duration){
//console.log(chartData);
var chart = $('.chart').highcharts({
chart: {
renderTo: 'chartContainer',
type: 'column',
height: windowHeight - 220, //Set chartsize depending on size of window
reflow: true
},
title: {
text: "title"
},
subtitle: {
text: "Source: "
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
},
yAxis: {
min: 0,
max: null,
title: {
text: 'Energy (kWh)'
}
},
"tooltip": {},
plotOptions: {
column: {
animation: {
duration: duration
},
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: data //Calculated data
})
.highcharts(); // return chart
}
Sure, you can extract the current chart settings by calling chart.highcharts(), it contains each axis which will have the effective min and max as well as the data's min/max set based on the series that are using it. 当然,您可以通过调用chart.highcharts()来提取当前图表设置,它包含将具有有效最小值和最大值的每个轴以及基于使用它的系列设置的数据最小值/最大值。
yAxis[0] would work if you only have one, but setting an id on the Axis might be clearer: 如果只有一个,yAxis [0]会起作用,但在Axis上设置id可能更清楚:
var chart = highcharts({...
yAxis: {
id: 'my_y',
...
yAxis = chart.highcharts().get('my_y');
yAxis.getExtremes(); // {min:, max:, dataMin:, dataMax:}
yAxis.setExtremes(newmin, newmax);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.