gpt4 book ai didi

javascript - Highcharts Add Annotation 不是动态添加的函数

转载 作者:行者123 更新时间:2023-11-30 20:57:08 25 4
gpt4 key购买 nike

我目前有一个有效的 highcharts 折线图(版本 6.0.3)。我有多个系列正在实时更新。我希望向点添加注释,通过 ID 链接,随着我更动态地添加,注释会跟随该点。例如,我将它添加到索引 3 处的点,并且当我添加更多时,注释向左移动到数组 [3] 处的点。

我目前遇到的问题是动态添加注解。以下是我的图表选项的设置方式:

  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...");
}

图表设置没有任何问题。从我的 API 检索数据时,我想动态添加注释,因此我从图表中获取系列,然后尝试使用以下方法添加注释:

     function addAnnotationToChartPoint(point, annotationText) {
_trendToolChart.addAnnotation({
linkedTo: point.Id,
title: annotationText
});
}

point.Id是一个guid,annotationText是一个字符串。

但是当我调用该函数时出现此错误:

TypeError: _trendToolChart.addAnnotation is not a function at addAnnotationToChartPoint (.js:865)

我可以在图表的选项和 userOptions 数组中看到注释,但该函数不存在。我需要先设置什么吗?

最佳答案

嗯,最简单(最愚蠢)的答案通常是正确的。看来我的注释 js 文件没有包含在我的 html 中。添加了这一行,我很高兴:

<script src="../Scripts/HighCharts/highcharts.js"></script>

关于javascript - Highcharts Add Annotation 不是动态添加的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47536595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com