Я искал решение, чтобы получить plotBand пути id, чтобы скрыть его с помощью серии. Основываясь на фрагменте r00tGER я сделал функцию, чтобы позвонить:
/**
* Get the plotBand or plotLine with given id out of all plotBands and plotLines of one Axis
* @param id The id of the plotBand or plotLine you are looking for
* @param axis The axis where the plotBand/plotLine is bound
*/
function getPlotBandOrLineById(id, axis) {
// loop through all plotBands/plotLines and check their id
for (var i = 0; i < axis.plotLinesAndBands.length; i++) {
if (axis.plotLinesAndBands[i].id === id) {
return axis.plotLinesAndBands[i];
}
}
}
С этой функцией вы можете скрыть и показать на plotBand (или сюжетный) с их серией:
$(function() {
$('#chart_container').highcharts('StockChart', {
...
series: [
{
name: 'Carbs',
...
events: {
show: function() {
var plotBand = getPlotBandOrLineById('goal_carbs', this.chart.yAxis[0]);
plotBand.hidden = false;
plotBand.svgElem.show();
},
hide: function() {
var plotBand = getPlotBandOrLineById('goal_carbs', this.chart.yAxis[0]);
plotBand.hidden = true;
plotBand.svgElem.hide();
},
},
},
],
...
});
});
Спасибо за ответ. Все мои PlotLines получают уникальный идентификатор при создании. Но как я могу получить объект PlotLine из диаграммы по id? Что-то вроде этого - chartX.xAxis [0] .getPlotLine (plotId); – r00tGER