Karine
Karine

Reputation: 621

Highcharts custom symbol legend

I need to custom the legend symbol for my chart

legend

I use Highcharts.js. I try several solutions without success :

here the fiddle : jsfiddle

Is it possible ? How can I achieve this ?

Thanks in advance.

Upvotes: 2

Views: 1498

Answers (1)

morganfree
morganfree

Reputation: 12472

You can achieve the desired result with html usage. In the label formatter make a div container for the text and the box. Set background color to the points color. Space between legend's items can be set with legend.itemMarginBottom/Top.

legend: {
  enabled: true,
  align: 'left',
  verticalAlign: 'top',
  layout: 'vertical',
  useHTML: true,
  symbolHeight: 0,
  symbolWidth: 0,
  itemMarginTop: 4,
  itemMarginBottom: 4,
  labelFormatter: function() {
    return '<div><div style="width:70px;display:inline-block;padding:3px 2px 3px 2px;text-align:center;color:#FFF;background-color:' + this.color + '">47.000€</div>    <b>' + this.name + '</b></div>';
  }
},

example: https://jsfiddle.net/5n7fue7m/

legend with coloured boxes

Upvotes: 4

Related Questions