Bill Huertas
Bill Huertas

Reputation: 746

How to add background colors to category groupings in Highcharts

I have a column chart rendered through Highcharts with multiple categories and multiple series. While Highcharts graciously groups and aligns the series data by categories, there does not appear to be a configuration option that would allow setting a background color for the category groupings.

I'd like to achieve a zebra striping by category, like this crude mockup I made in Photoshop®: enter image description here

Here's a jsfiddle containing my current code, and my current chart configuration:

var chartOptions = {
  "chart": {
    "type": "column"
  },
  "title": {
    "text": ""
  },
  "credits": {
    "enabled": false
  },
  "subtitle": {
    "text": ""
  },
  "xAxis": {
    "categories": [
      "Category 1",
      "Category 2",
      "Category 3",
      "Category 4",
      "Category 5",
      "Category 6"
    ],
    "opposite": true
  },
  "yAxis": {
    "title": {
      "text": "Score"
    },
    "tickPixelInterval": 40
  },
  "plotOptions": {
    "column": {
      "pointPadding": 0.2,
      "borderWidth": 0
    }
  },
  "series": [
    {
      "name": "Series 1",
      "data": [22.735, 5.9, -18.71, -41.17, -0.865, -6.03]
    },
    {
      "name": "Series 2",
      "data": [20.67, 5.46, -17.15, -37.66, -0.79, -5.52]
    },
    {
      "name": "Series 3",
      "data": [29, 2, -20, -29, -2, 16]
    }
  ]
};

Upvotes: 3

Views: 1106

Answers (1)

97ldave
97ldave

Reputation: 5249

You can use the alternateGridColor option on xAxis:

"xAxis": {
    "categories": [
      "Category 1",
      "Category 2",
      "Category 3",
      "Category 4",
      "Category 5",
      "Category 6"
    ],
    "opposite": true,
     alternateGridColor: '#CCC'

If you look at the xAxis documentation there are quite a few different properties you can use.

Demo

Upvotes: 5

Related Questions