简体   繁体   English

将标签添加到Highcharts中的行

[英]Add label to line in Highcharts

I struggle to add a label on top of a line in highcharts .. for example suppose I have 4 series (all visible) with name 'data' , 'mean' , '+1 std' , '-1 std' : 我努力在高图的一行顶部添加标签。例如,假设我有4个系列(全部可见),名称为'data''mean''+1 std''-1 std'

在此处输入图片说明

And I would like as a result: 结果,我希望:

在此处输入图片说明

I am lost to know how to add it ... even with the documentation it seems I need the abscissa and ordinate to add for each label. 我不知道该如何添加...即使使用文档,似乎我也需要为每个标签添加横坐标和纵坐标。 How can I retrieve this information? 如何获取此信息? Is it possible to add the label directly when I add the series? 添加系列时是否可以直接添加标签?

        chart.addSeries({
            id           : 'mean',
            name         : 'mean',
            type         : 'line',
            lineWidth    : 1,
            lineColor    : 'rgba(0,128,0,0.9)',
            color        : 'rgba(0,128,0,0.9)',
            dashStyle    : 'LongDash',
            zIndex       : 5,
            data         : [[ext.dataMin, mean], [ext.dataMax, mean]],
            enableMouseTracking: false
        });

Notice that I do not want to display this information in a legend, but on the chart itself- 请注意,我不想在图例中显示此信息,而是在图表本身上显示-

You can do this with a dataLabel . 您可以使用dataLabel进行此dataLabel

If you disable dataLabels in the plotOptions, but enable them on the first point of each series, you will get exactly what you're asking for. 如果您在plotOptions中禁用了dataLabels,但是在每个系列的第一点启用了它们,您将得到您所需要的。

Code example: 代码示例:

   data: [
    {
        x:0,
      y:5,
      dataLabels:{ 
        enabled: true,
        format: 'label 1: {y}'
      }
    },
    [10,5]
  ] 

Fiddle example: 小提琴的例子:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM