javascript - Add label to line in Highcharts - Stack Overflow

I struggle to add a label on top of a line in highcharts .. for example suppose I have 4 series (all vi

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-

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-

Share Improve this question asked Jan 13, 2016 at 13:49 Colonel BeauvelColonel Beauvel 31.2k11 gold badges48 silver badges88 bronze badges 1
  • You can use renderer , replace your lines with plotLines and use label – Sebastian Bochan Commented Jan 13, 2016 at 14:49
Add a ment  | 

1 Answer 1

Reset to default 5

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:

  • http://jsfiddle/jlbriggs/vtmqLzer/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745460205a4628674.html

相关推荐

  • javascript - Add label to line in Highcharts - Stack Overflow

    I struggle to add a label on top of a line in highcharts .. for example suppose I have 4 series (all vi

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信