我有一些代码在将线条添加到图表时创建一个按钮。单击按钮时,我想从图表中删除线条并删除按钮。该示例可以在这里查看。
也就是说,成功添加按钮的代码是:
function getChartData(option){
var category = $('#category').val();
var option = option.value;
var seriesTitle = category+option;
$.ajax({
url: "getData.php?action=getChartData",
type: "GET",
dataType:"json",
data: {
category:category,
option:option
},
success: function(json){
chart.addSeries({
name: seriesTitle,
data : []
});
$.each(json.Data,function(){
chart.series[chart.series.length-1].addPoint([parseFloat(this.Year), parseFloat(this[option])]);
});
}
});
var series = document.createElement('button');
series.onclick = function(){
removeLine(seriesTitle);
}
series.setAttribute('id',seriesTitle);
series.innerHTML=seriesTitle;
$('#removeLine').append(series);
}
然后,当单击按钮时,此代码不执行任何操作:
function removeLine(seriesTitle){
chart.series[seriesTitle].remove();
$(seriesTitle).remove();
}
错误是:
Uncaught TypeError: Cannot call method 'remove' of undefined
removeLine oil.js:172
series.onclick
任何知道我如何根据变量在 highcharts 中调用特定行的人的奖励积分,例如:
chart.series[chart.series.length-1].remove();
这不会:
chart.series[seriesTitle].remove();