我正在研究Highcharts,并尝试通过单击按钮在系列之间切换-通过按钮而不是图例打开和关闭系列。我们可以使用Javascript吗?
答案 0 :(得分:0)
使用chart.series[seriesNumber].hide()
。参考[https://api.highcharts.com/class-reference/Highcharts.Series#hide]
$( document ).ready(function() {
$('#container').highcharts({
series: [{
data: [120, 20, 50, 100, 510, 345, 120]
}, {
data: [132, 240, 444, 424, 230, 350, 330]
}]
});
// the button action
var chart = $('#container').highcharts();
$('.button').click(function(){
var seriesNumber = this.value;
var series = chart.series[seriesNumber];
if (series.visible) {
series.hide();
} else {
series.show();
}
});
});
.button {
width: 150px;
}
#container {
height: 250px;
}
<!DOCTYPE html>
<html>
<head>
<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>
</head>
<body>
<input type="button" class="button" value="0"></input>
<input type="button" class="button" value="1"></input>
<div id="container"></div>
</body>
</html>