I currently have a working highcharts line chart (version 6.0.3). I have multiple series where I am live updating. I am looking to add annotations to the points, linked by an ID, that follow the point as I add more dynamically. For example, I add it to point at index 3, and as I add more, the annotation shuffles to the left with the point at array[3].
The problem I currently have is dynamically adding annotations. Here is how my chart options are setup:
function createTrendTool() {
_trendToolChart = Highcharts.chart('trendToolContainer', {
chart: {
type: 'spline',
zoomType: 'x',
panning: true,
panKey: 'shift'
},
tooltip: {
formatter: function () {
var unit = this.series.userOptions.Unit;
if (unit) { unit = ' ' + unit; }
var s = '<b>' + this.series.name + '</b>';
s += '<br/>' + moment(this.x).format('MMM D YYYY HH:mm:ss') +
'<br/>' + this.y + unit;
return s;
}
},
annotations: [{
labelOptions: {
backgroundColor: 'rgba(255,255,255,0.5)',
verticalAlign: 'top',
y: 15
},
labels:[]
}],
title: {
text: 'Trending Signals'
},
credits: false,
yAxis: {
title: {
text: 'Values'
}
},
xAxis: {
title: {
text: 'Time'
},
type: 'datetime'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
label: {
connectorAllowed: true
}
}
},
responsive: {
rules: [{
condition: {
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});
_trendToolChart.showLoading("Loading...");
}
The chart setups without any issues. On retrieving data from my API, I want to dynamically add an annotation, so I grab the series from my chart and then try to add the annotation with this:
function addAnnotationToChartPoint(point, annotationText) {
_trendToolChart.addAnnotation({
linkedTo: point.Id,
title: annotationText
});
}
The point.Id is a guid, and the annotationText is a string.
But when I call the function I get this error:
TypeError: _trendToolChart.addAnnotation is not a function at addAnnotationToChartPoint (.js:865)
I can see annotations listed in the options and userOptions array on the chart, but the function isn't there. Is there something I need to setup first?