2

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';
Mikev
  • 2,012
  • 1
  • 15
  • 27
Segamoto
  • 315
  • 4
  • 13

2 Answers2

3

Swap the area.prototype.drawLegendSymbol method with line.prototype.drawLegendSymbol. This is enough in pure JS:

Highcharts.seriesTypes.area.prototype.drawLegendSymbol =
Highcharts.seriesTypes.line.prototype.drawLegendSymbol;

jsFiddle

In angular you can wrap Highcharts this way:

(function(factory) {
  if (typeof module === "object" && module.exports) {
    module.exports = factory;
  } else {
    factory(Highcharts);
  }
})(function(Highcharts) {
  Highcharts.seriesTypes.area.prototype.drawLegendSymbol =
    Highcharts.seriesTypes.line.prototype.drawLegendSymbol;
});

docs: https://github.com/highcharts/highcharts-angular#to-load-a-wrapper

raf18seb
  • 2,096
  • 1
  • 7
  • 19
  • Same here: That works for the label, but for the tooltip is a fail – Merak Marey Feb 20 '19 at 15:27
  • For angular is not possible do this. I haven't `seriesTypes` – Segamoto Feb 20 '19 at 15:34
  • It is a default tooltip 'sign' even for a line or any other series. If you want to change this, you can do this in tooltip.formatter function line in this example: https://jsfiddle.net/BlackLabel/kcr1oynf @Segamoto of course it is possible. I will edit my answer. – raf18seb Feb 20 '19 at 15:57
2

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.

Kabulan0lak
  • 2,116
  • 1
  • 19
  • 34