Sankey diagram

author(s): Torstein Hønsi

by Baliga

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/sankey.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>
    <p class="highcharts-description">
        Sankey charts are used to visualize data flow and volume
        between nodes. The wider lines indicate larger volumes.
    </p>
</figure>

CSS

#csv {
    display: none;
}

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

.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', {
  title: {
    text: 'Highcharts Sankey Diagram'
  },
  series: [{
    keys: ['to', 'from', 'weight'],
    data: [
      ['Oil', 'Transportation', 94],
      ['Natural Gas', 'Transportation', 3],
      ['Coal', 'Transportation', 0],
      ['Renewable', 'Transportation', 0],
      ['Nuclear', 'Transportation', 3],
      ['Oil', 'Industrial', 41],
      ['Natural Gas', 'Industrial', 40],
      ['Coal', 'Industrial', 7],
      ['Renewable', 'Industrial', 11],
      ['Nuclear', 'Industrial', 0],
      ['Oil', 'Residential & Commercial', 17],
      ['Natural Gas', 'Residential & Commercial', 76],
      ['Coal', 'Residential & Commercial', 1],
      ['Renewable', 'Residential & Commercial', 7],
      ['Nuclear', 'Residential & Commercial', 0],
      ['Oil', 'Electric Power', 1],
      ['Natural Gas', 'Electric Power', 18],
      ['Coal', 'Electric Power', 48],
      ['Renewable', 'Electric Power', 11],
      ['Nuclear', 'Electric Power', 22],
      ['A', 'Nuclear', 11],
      ['B', 'Nuclear', 4],
      ['C', 'Nuclear', 1],
      ['D', 'Nuclear', 9],
    ],
    type: 'sankey',
    name: 'Sankey demo series',
    nodes: [{
      id: 'Nuclear',
      color: '#ffa500',
      offset: 150,
	  column: 1
    }]
  }]
});