我很想知道为什么按钮 2 在此示例中不起作用
在这个 jsfiddle 示例中,附加到按钮 1 的“更新”方法正在工作,但在我的原始代码中,“更新”也不起作用。它显示错误:“object# has no method 'update'”
$(function () {
var options= {
chart: {
renderTo: 'container',
height: 400
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
};
var chart = new Highcharts.Chart(options);
buttonhandle1();
buttonhandle2()
});
function buttonhandle1(){
$("#b1").click(function(){
var chart = $('#container').highcharts();
chart.yAxis[0].update({
min:0,
max: 5,
tickInterval : 1,
});
});
}
function buttonhandle2(){
var chart = $('#container').highcharts();
$("#b2").click(function(){
chart.yAxis[0].min= 0;
chart.yAxis[0].max= 5;
chart.yAxis[0].tickInterval = 1;
chart.redraw();
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<button id="b1"> button 1</button>
<button id="b2"> button 2</button>