JSFiddle - React, Tailwind, and code Playground
by zstone422
HTML
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="sankey_basic" style="width: 900px; height: 300px;"></div>
JavaScript
google.charts.load('current', {'packages':['sankey']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'From');
data.addColumn('string', 'To');
data.addColumn('number', 'Weight');
data.addRows([
[ 'BELOW 2017 (N=11,870)', 'MASTERED 2018', 6],
[ 'BELOW 2017 (N=11,870)', 'ON TRACK 2018', 57 ],
[ 'BELOW 2017 (N=11,870)', 'APPROACHING 2018', 1907],
[ 'BELOW 2017 (N=11,870)', 'BELOW 2018', 9900],
]);
// Sets chart options.
var colors = ['#d7191c', '#1a9641', '#a6d96a', '#fdae61',
'#d7191c'];
var options = {
width: 800, height: 600,
sankey: {
iterations: 100,
node: {
colors: colors,
label: {fontName: 'Arial',
fontSize: 12,
bold: true,}
},
link: {
colorMode: 'gradient',
colors: colors
}
}};
// Instantiates and draws our chart, passing in some options.
var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
chart.draw(data, options);
}