Search code examples
highchartscolorsbackgroundbar-chartstacked-chart

add background color to highcharts stacked Bar Chart


How i can add background color to highcharts stacked Bar Chart column like in picture

enter image description here

I have try find in highcharts official documentation but unfortunately cant find.


Solution

  • There is no straight way from the API to create such a shadow background for a stacked bar chart, but you can create it as a dummy series with disabled enableMouseTracking and showInLegend options.

    Sample code:

      plotOptions: {
        bar: {
          stacking: 'percent'
        }
      },
      series: [{
          color: '#ddd',
          enableMouseTracking: false,
          showInLegend: false,
          data: [7, 7]
        }, {
          data: [1, 1]
        },
        {
          data: [2, 2]
        }
      ]
    

    Demo: https://jsfiddle.net/BlackLabel/7vx2sn8d/

    API References: https://api.highcharts.com/highcharts/series.bar.showInLegend https://api.highcharts.com/highcharts/series.bar.enableMouseTracking