Sankey diagram

author(s): Torstein Hønsi

by koh_edwin

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'
    },
    accessibility: {
        point: {
            valueDescriptionFormat: '{index}. {point.from} to {point.to}, {point.weight}.'
        }
    },
    series: [{
        keys: ['from', 'to', 'weight'],
        data: [
            ['ST Inv', 'Income Mid Retirement', 2],
            ['ST Inv', 'ST Mid Retirement', 1],
            ['MT Inv', 'ST Mid Retirement', 2],
            ['MT Inv', 'MT Mid Retirement', 2],
            ['LT Inv', 'LT Mid Retirement', 3],
            ['ST Mid Retirement', 'Income Later Years', 1],
            ['ST Mid Retirement', 'ST Later Years', 1],
            ['MT Mid Retirement', 'ST Later Years', 1],
            ['MT Mid Retirement', 'MT Later Years', 2],
            ['LT Mid Retirement', 'Income Later Years', 2],
            ['LT Mid Retirement', 'LT Later Years', 2]
        ],
        nodes: [{
        id: 'ST Inv',
        //name: 'R1',
        color: '#DDDF00'
      },
      {
        id: 'MT Inv',
        //name: 'R1',
        color: '#24CBE5'
      },
      {id: 'LT Inv',color: '#64E572'},
      {id: 'Income Mid Retirement',color: '#756bb1'},
      {id: 'Income Later Years',color: '#756bb1'},
      {id: 'LT Mid Retirement',color: '#64E572'},
      {id: 'LT Later Years',color: '#64E572'},
      {id: 'ST Mid Retirement',color: '#DDDF00'},
      {id: 'ST Later Years',color: '#DDDF00'},
      {id: 'MT Mid Retirement',color: '#24CBE5'},
      {id: 'MT Later Years',color: '#24CBE5'}
     
    ],
        type: 'sankey',
        name: 'Sankey demo series'
    }]

});