gpt4 book ai didi

javascript - Highcharts - 使用 setData() 更新柱形图不起作用

转载 作者:行者123 更新时间:2023-11-29 10:14:44 24 4
gpt4 key购买 nike

<分区>

我有一个柱形图,当用户从下拉菜单中选择一个选项时,我想更新它。我能够正确呈现柱形图,但无法使用 setData() 更新该图。我有点难过,因为我没有收到任何错误。您能给我的任何帮助或见解将不胜感激!这是我的 JSFiddle 的链接

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 {

}
});

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com