首页 > 解决方案 > highcharts - 通过自定义 id 添加标签

问题描述

我有一个温度传感器数据的迷你图,它每 1 分钟采样一年的数据

我首先加载一个空白图表,然后进行服务器调用,将结果返回并通过调用显示它

getchart.addSeries({
 name: thisGroup,
 id: probeItem[0],
 data: probeDataArray,
 keys: ['x', 'y', 'specialId'],

最多可以有 20 个系列,它们都一个一个地加载到屏幕上 这渲染得非常快,但是我现在需要在温度超过某个值的地方添加一个标签注释(即在其警报状态时添加一个警告符号)

目前我正在遍历每个点并查看它是否超过某个值:

currentSeries.points.forEach(function (point) {

然而,这是非常缓慢的。

我有一组警报,可以将它们引用为

['x', 'y', 'specialId']

但是我看不到如何通过 x、y 或 specialId 添加注释标签。

如果我遍历所有已渲染的点,我似乎只能添加标签

有没有办法使用我的 ID 添加标签?我还需要调整图形和标签的大小以保持在同一个地方

或者,如果这是不可能的,是否在我添加系列时添加标签?:

  getchart.addSeries({
                    name: thisGroup,
                    id: CurrentGroupID,
                    dashStyle: 'ShortDot',
                    data: groupLogArray,
                    keys: ['x', 'y', 'specialId'],
                    showInNavigator: true, //this shows the series data in the small bottom navigator
                    point: {
                        events: {
                            click: function () {
                                //alert("test click");                                
                            }
                        }
                    }
                });

标签: highcharts

解决方案


x您可以通过和y轴值添加注释:

chart.addAnnotation({
    labels: [{
        text: 'Alarm',
        point: {
            x: 2,
            y: 3,
            xAxis: 0,
            yAxis: 0
        }
    }]
});

现场演示:http: //jsfiddle.net/BlackLabel/k6trha3e/

API 参考: https ://api.highcharts.com/class-reference/Highcharts.Chart#addAnnotation


作为替代方案,您还可以使用数据标签:http: //jsfiddle.net/BlackLabel/n4586xzq/


推荐阅读