Highcharts Line Chart, display series name at the end of line series

前端 未结 2 1572
故里飘歌
故里飘歌 2021-01-28 01:04

We have requirement for line chart as below. We are using highcharts. Our requirement is that chart should display series name at the end of line as displayed in below images. <

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 01:57

    Get last point, which has plotX and plotY properties, then draw your labels with render.

    const options = {
      chart: {
        events: {
          load() {
            const chart = this
            const series = chart.series
    
            series.forEach((s) => {
              const len = s.data.length
              const point = s.data[len - 1]
              console.log(point)
    
              chart.renderer.text(
                point.series.name,
                point.plotX + chart.plotLeft + 10,
                point.plotY + chart.plotTop - 10
              )
              .attr({
                zIndex: 5
              })
              .add()
            })
          }
        }
      },
      xAxis: {
        max: 5
      },
      series: [{
        data: [30, 70, 50, 90]
      }, {
        data: [60, 100, 80, 120]
      }, {
        data: [80, 150, 90, 180]
      }]
    }
    
    const chart = Highcharts.chart('container', options)
    

    Live example:

    https://jsfiddle.net/479vdhm3/

提交回复
热议问题