Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

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

enter image description here

And I would like as a result:

enter image description here

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-

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...