Search code examples
javascriptangularchartshighchartsangular2-highcharts

Angular Highcharts Custom Legend Label In Area Chart


I've to customize label symbol in area chart type as it can done in line chart type:

I've this code:

Highcharts.chart('container', {
        chart: {
        type: 'area'
    },

    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    plotOptions: {
        series: {
            marker: {
                enabled: false
            }
        }
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});

My legend is like this: Result

I expect to have this: enter image description here

I can't edit css style, this must be an exclusive customization for only this chart.

I'm using angular 7.2, I've imported Highchart with this:

import {Chart} from 'angular-highcharts';

Solution

  • You can achieve that by manually setting width and height of the legend symbols. You need to set squareSymbol to false to allow having different values for width and height:

    legend: {
        squareSymbol: false,
        symbolHeight: 3,
        symbolWidth: 20
    },
    

    For example.

    EDIT

    If you want to align the symbol with text, use useHTML: true and set the lineHeight:

      legend: {
        useHTML: true,
        itemStyle: {
          lineHeight: "23px"
        },
        squareSymbol: false,
        symbolHeight: 3,
        symbolWidth: 20
      },
    

    See updated working jsfiddle here.