Created
September 5, 2019 23:47
-
-
Save adept/fcef2ba03100fb5d61df06b476ca4f22 to your computer and use it in GitHub Desktop.
Google Charts Sankey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
<div id="sankey_multiple" style="width: 1800px; height: 1200px;"></div> | |
<script type="text/javascript"> | |
var raw_data = []; | |
d3.csv("sankey.csv", function(error, data) { | |
console.log(error); | |
data.forEach(function (d) { | |
console.log(d); | |
raw_data.push([d.source, d.target, +d.value]); | |
}); | |
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(raw_data); | |
// Set chart options | |
var options = { | |
width: 1600, | |
}; | |
// Instantiate and draw our chart, passing in some options. | |
var chart = new google.visualization.Sankey(document.getElementById('sankey_multiple')); | |
chart.draw(data, options); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment