Stacked and grouped column

author(s): Torstein Hønsi

by oysteinmoseng

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
</figure>

CSS

.highcharts-figure,
.highcharts-data-table table {
    min-width: 310px;
    max-width: 800px;
    margin: 1em auto;
}

#container {
    height: 550px;
}

.highcharts-data-table table {
    font-family: Verdana, sans-serif;
    border-collapse: collapse;
    border: 1px solid #ebebeb;
    margin: 10px auto;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}

.highcharts-data-table th {
    font-weight: 600;
    padding: 0.5em;
}

.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
    padding: 0.5em;
}

.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}

.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

Highcharts.chart('container', {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Directors with Greatest Number of Award Wins'
  },
  xAxis: {
    categories: ['Ethan & Joel Coen', 'Lee Unkrich', 'Steven Spielberg', 'George Lucas', 'David Fincher', 'Curtis Hanson', 'Ang Lee', 'Terrence Malick', 'Benh Zeitlin', 'Roberto Benigni'],
    title: {
      text: 'director'
    }
  },
  yAxis: {
    min: 0,
    title: {
      text: 'sum ( awards wins )'
    },
    stackLabels: {
      enabled: true,
      style: {
        fontWeight: 'bold',
        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
      }
    }
  },
  legend: {
    align: 'right',
    x: -30,
    verticalAlign: 'top',
    y: 25,
    floating: true,
    backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
    borderColor: '#CCC',
    borderWidth: 1,
    shadow: false
  },
  tooltip: {
    headerFormat: '<b>{point.x}</b><br/>',
    pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
  },
  plotOptions: {
    column: {
      stacking: 'normal',
      dataLabels: {
        enabled: true,
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
      }
    }
  },
  series: [{
    name: 'Action',
    data: [350, 50, 20, 10, 40, 100, 50, 80, 70, 50, 60]
  }, {
    name: 'Adventure',
    data: [30, 90, 30, 20, 20, 40, 40, 10, 20, 10, 10]
  }, {
    name: 'Animation',
    data: [20, 180, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  }, {
    name: 'Biography',
    data: [0, 0, 60, 0, 20, 10, 0, 20, 20, 0, 0]
  }, {
    name: 'Comedy',
    data: [0, 0, 20, 30, 0, 0, 30, 0, 0, 30, 0]
  }, {
    name: 'Crime',
    data: [0, 0, 30, 40, 10, 20, 0, 0, 0, 10, 20]
  }, {
    name: 'Drama',
    data: [0, 0, 40, 40, 30, 20, 40, 10, 40, 10, 30]
  }, {
    name: 'Family',
    data: [0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  }, {
    name: 'Fantasy',
    data: [0, 10, 10, 0, 0, 20, 0, 10, 0, 10, 0]
  }, {
    name: 'Horror',
    data: [0, 0, 0, 0, 0, 0, 20,...