Javascript 从比较图表中删除图表系列
试图从包含5个图表系列的比较图表中删除其中一个图表 有五个复选框,每个复选框都在复选框中添加图表…如果复选框取消选中,图表将被删除。我尝试了chart.series[2],但如果按钮1、2和3被选中,则图表显示全部三个,如果取消选中第二个复选框,则图表2不会熄灭,而是显示全部三个,其他3、4和5也一样Javascript 从比较图表中删除图表系列,javascript,highcharts,highstock,Javascript,Highcharts,Highstock,试图从包含5个图表系列的比较图表中删除其中一个图表 有五个复选框,每个复选框都在复选框中添加图表…如果复选框取消选中,图表将被删除。我尝试了chart.series[2],但如果按钮1、2和3被选中,则图表显示全部三个,如果取消选中第二个复选框,则图表2不会熄灭,而是显示全部三个,其他3、4和5也一样 $('li').click(function (evt) { if ($(this).attr("class") == "BtnA" || $(this).attr("class") == "Bt
$('li').click(function (evt) { if ($(this).attr("class") == "BtnA" || $(this).attr("class") == "BtnB" || $(this).attr("class") == "BtnC" || $(this).attr("class") == "BtnD" || $(this).attr("class") == "BtnE") {
$(this).addClass("selected");
if ($(this).addClass("selected")) {
switch ($(this).attr("class")) {
case "BtnA selected": testing_name = "test1"; names = 'testname1';
break;
case "BtnB selected": testing_name = "test2"; names = 'testname2';
break;
case "BtnC selected": testing_name = "test3"; names = 'testname3';
break;
case "BtnD selected": testing_name = "test4"; names = 'testname4';
break;
case "BtnE selected": testing_name = "test5"; names = 'testname5';
break;
}
chart(testing_name, names);
}else if ($(this).attr("class") == "BtnA selected" || $(this).attr("class") == "BtnB selected" || $(this).attr("class") == "BtnC selected" || $(this).attr("class") == "BtnD selected" || $(this).attr("class") == "BtnD selected") {
$(this).removeClass("selected");
$('li').each(function () {
$('#container').charts('tested').series[2].hide();
}
以及对图表的函数调用
function chart(testing_name, names) {
$(function () {
var seriesOptions = [],
yAxisOptions = [],
seriesCounter = 0;
if (data == 0) {
series_names = ["data"];
jsonfilename = ["datajson"];
}
data++;
series_names.push(names);
jsonfilename.push(testing_name);
$.each(series_names, function (i, name) {
$.getJSON(jsonfilename[i] + ".txt", function (data) {
seriesOptions[i] = {
name: name,
data: data
};
seriesCounter++;
if (seriesCounter == series_names.length) {
createChart();
}
});
});
// create the chart when all data is loaded
function createChart() {
$('#container').highcharts('StockChart', {
rangeSelector: {
inputEnabled: $('#container').width() > 480,
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? '+' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2
},
series: seriesOptions
});
}
});
}
能否请您提供任何参考代码来实现这一点
谢谢和问候,
ShailShin图表的HTML看起来像什么?看起来像什么-Highstock demo-比较多个系列我发现很难想象你的页面看起来像什么。在任何情况下,您都应该在复选框中添加一个事件侦听器,并删除/隐藏相应的表。也许您可以用jsfiddle.netSo演示您需要销毁序列或图表?如果需要隐藏序列,可以调用function