Warm tip: This article is reproduced from serverfault.com, please click

Highcharts: Removing the legend Symbol that comes with marker

发布于 2020-11-30 08:25:30

I have a line chart with marker enabled. I also have my own custom legend Formatter

legend: {
        enabled: true,
        useHTML: true,
        labelFormatter: function() {
            let symbol = '<span style="color:' + this.color + ';font-size:12px;">&#9644;</span>';
            return '<span style="font-size: 12px;">' + symbol +  ' ' + this.name  +  '</span>';
        }
    }

Because of my marker, I get an additional line next to my custom legend symbol. I tried destroying my marker symbols using this solution LINK: http://jsfiddle.net/Tr7nk/2621/ But , I am getting errors when toggling the legends

ERROR TypeError: Cannot read property 'isSVG' of undefined
    at E.destroy (highcharts.src.js:4424)
    at t.<anonymous> (chart.component.ts:271)
    at Function.each (jquery.min.js:2)

Please help. thanks

Questioner
Kavvya Ramarathnam
Viewed
0
ppotaczek 2020-11-30 23:52:18

Instead of destroying the legend symbol, you can set symbolWidth to 0, to make it invisible.

    legend: {
        ...,
        symbolWidth: 0
    }

Live demo: http://jsfiddle.net/BlackLabel/mwpu26sj/

API Reference: https://api.highcharts.com/highcharts/legend.symbolWidth