Search code examples
labelhighchartsrenderer

How to draw Yaxis label in highcharts


Is there any way to draw Yaxis lable using highcharts/highstock api? The value of the label will be the end value of the series. The color will be the same color of the series.

I found there is a renderer api, but is seems it is difficult to know the exact position of the point.

yaxis label


Solution

  • Here's an older example that uses the renderer function:

    http://jsfiddle.net/jlbriggs/4FrGG/4/

    function(chart){
        $(chart.series).each(function(i, serie){
            //to get the appropraite 'y' position
            var point = serie.data[serie.data.length-1];
            chart.renderer.text(
                //the text to render
                '<span style="font-weight:bold;color:' + serie.color + ';">' + serie.name + '</span>',
                //the 'x' position
                chart.plotLeft+chart.plotWidth+5,
                //the 'y' position
                chart.plotTop + point.plotY+3).add()
        });
    });
    

    You could also do it by using data labels, enabled for only the last data point:

    http://jsfiddle.net/jlbriggs/zXLZA/0/

    You could also do it now by using the 'tickPositions' property, and then the formatter function on the axis labels

    http://api.highcharts.com/highcharts#yAxis.tickPositions

    http://api.highcharts.com/highcharts#yAxis.labels.formatter