我有一个列图,我想在用户从下拉菜单中选择一个选项时进行更新。 我能够正确渲染列图,但我无法使用setData()更新图。我有点难过,因为我没有收到任何错误。任何帮助或见解,你可以给我非常感谢!这里是一个链接到我的jsfiddleHighcharts - 使用setData()更新列图不工作
http://jsfiddle.net/mshirk/6QYzD/2/
和JavaScript代码绘制图形
$(document).ready(function() {
var chartBench = new Highcharts.Chart({
chart: {
renderTo: 'containerYo',
type: 'column'
},
title: {
text: ''
},
credits: {
enabled: false
},
legend: {},
plotOptions: {
series: {
shadow: false,
borderWidth: 0
}
},
xAxis: {
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickLength: 3,
categories: ['2011', '2012', '2013', '2014'],
title: {
text: 'Years'
}
},
yAxis: {
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickWidth: 1,
tickLength: 3,
gridLineColor: '#ddd',
labels: {
format: '$ {value}'
},
title: {
text: ''
}
},
series: [{
"name": "Yours",
"data": [110, 100, 120, 130]
}, {
"name": "Another",
"data": [100, 90, 110, 120]
}, {
"name": "Another B",
"data": [90, 80, 100, 110]
}, {
"name": "Another C",
"data": [80, 70, 90, 100]
}]
});
});
$("#list").on('change', function() {
//alert('f')
var selVal = $("#list").val();
if (selVal == "a") {
chartBench.series[0].setData([
[{
"name": "Yours",
"data": [110, 100, 120, 130]
}, {
"name": "Another",
"data": [100, 90, 110, 120]
}, {
"name": "Another B",
"data": [90, 80, 100, 110]
}, {
"name": "Another C",
"data": [80, 70, 90, 100]
}]
]);
} else if (selVal == "b") {
chartBench.series[0].setData([
[{
"name": "Yours",
"data": [210, 200, 220, 230]
}, {
"name": "Another",
"data": [200, 190, 210, 220]
}, {
"name": "Another B",
"data": [190, 180, 200, 210]
}, {
"name": "Another C",
"data": [180, 170, 190, 200]
}]
]);
} else {
}
});
“我没有收到任何错误”。检查你的控制台提示。 –
感谢您的帮助,但是在检查控制台时,我没有收到任何通知 – user3826864
如果您在下拉列表中选择了某些内容,它会在控制台中产生此错误:未捕获的ReferenceError:chartBench未定义。在list change事件中引用'chartBench'的范围是错误的。 –