简体   繁体   中英

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' :

在此处输入图片说明

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 .

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.

Code example:

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

Fiddle example:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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