{"id":14973,"date":"2022-05-25T14:32:13","date_gmt":"2022-05-25T14:32:13","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=14973"},"modified":"2022-08-13T11:11:27","modified_gmt":"2022-08-13T11:11:27","slug":"sankey-diagram-js","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/","title":{"rendered":"How to Create Sankey Diagram (with JavaScript)"},"content":{"rendered":"<p><a href=\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png\" alt=\"Sankey diagram in JavaScript HTML5\" width=\"100%\" class=\"alignnone size-full wp-image-15007\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png 1650w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-300x167.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-768x427.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-1024x569.png 1024w\" sizes=\"(max-width: 1650px) 100vw, 1650px\" \/><\/a>Would you like to learn how to quickly create a really cool chart called a Sankey diagram? You\u2019re in the right place! Together, we will build an elegant <a href=\"https:\/\/www.anychart.com\/chartopedia\/chart-type\/sankey-diagram\/\">Sankey chart<\/a> using JavaScript, and then you\u2019ll be able to produce such data visualizations by yourself with no hassle at all.<\/p>\n<p>Depicting the flow of values from one set to another, Sankey diagrams are ideal when you need to graphically represent a many-to-many mapping between two domains or multiple paths through a number of stages. So, competence in making them will be a great addition to the skill set of anyone dealing with <a href=\"https:\/\/www.anychart.com\/blog\/2018\/11\/20\/data-visualization-definition-history-examples\/\">data visualization<\/a> design and development.<\/p>\n<p>110 years after it sank on April 15, 1912, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Titanic\" target=\"_blank\" rel=\"nofollow\">Titanic<\/a> still holds us in its thrall, piquing people\u2019s imagination. Now, we will use the JS Sankey diagramming technique to look at its passengers and crew and find out who survived and perished based on gender, age, and ticket class. Follow along!<\/p>\n<p><!--more Read the JS charting tutorial \u00bb--><\/p>\n<h2>Sankey Diagram Preview<\/h2>\n<p>Take a glance at the Sankey diagram we will have built by the end of the tutorial:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram.gif\" alt=\"A Sankey diagram built with JavaScript HTML5, visualizing the destiny of the passengers and the crew of the Titanic\" width=\"100%\" class=\"alignnone size-full wp-image-15014\" \/><\/p>\n<p>Now, the journey begins \u2014\u00a0read on to learn how to build Sankey charts like this using pure JavaScript!<\/p>\n<h2>Building Basic JS Sankey Diagram<\/h2>\n<p>A Sankey diagram looks really exciting and is pretty easy to create with JS. Some basic knowledge of web technologies is always beneficial in interactive data visualization. But in reality, everything is uncomplicated and you will understand it all even if you are a beginner.<\/p>\n<p>The process of creating a JavaScript-based Sankey diagram can be split into four steps:<\/p>\n<ol>\n<li>Create an HTML page.<\/li>\n<li>Add scripts.<\/li>\n<li>Set data.<\/li>\n<li>Write some JS code.<\/li>\n<\/ol>\n<p>Let\u2019s go through them together.<\/p>\n<h3>1. Create an HTML page<\/h3>\n<p>To start with, create a basic HTML page to hold the intended Sankey chart and define a block element in it.<\/p>\n<p>To reference this <code>&lt;div&gt;<\/code> later in the code, give it an identification attribute (\u201ccontainer\u201d in this example) and set the desired style properties (here, the width and height are 100%, which will let the diagram stretch across the entire web page).<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Sankey Diagram&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>2. Add scripts<\/h3>\n<p>The next step is to add the necessary scripts.<\/p>\n<p>In this tutorial, I am using the <a href=\"https:\/\/www.anychart.com\">AnyChart JavaScript library<\/a>. It is flexible and easy to use thanks to its comprehensive <a href=\"https:\/\/docs.anychart.com\/\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> along with many readymade <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/\">chart examples<\/a>.<\/p>\n<p>AnyChart is modular, which lets you minimize the size of the JavaScript code running on your web page by connecting the chart types and features you actually need and nothing more. For the Sankey chart development, you just need the <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#core\" target=\"_blank\" rel=\"nofollow\">core module<\/a> along with the specific <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Modules#sankey_diagram\" target=\"_blank\" rel=\"nofollow\">Sankey module<\/a>. Add both to the <code>&lt;head&gt;<\/code> section of the HTML page.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Sankey Diagram&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-sankey.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;  \r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ All the code for the JS Sankey Diagram will come here.\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h3>3. Set data<\/h3>\n<p>Data for this tutorial is taken from the <a href=\"https:\/\/www.kaggle.com\/datasets\/ibrahimelsayed182\/titanic-dataset\" target=\"_blank\" rel=\"nofollow\">Titanic dataset<\/a> on Kaggle. I have only put it in a form <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Sankey_Diagram#data\" target=\"_blank\" rel=\"nofollow\">suitable<\/a> for a Sankey diagram.<\/p>\n<p>The dataset is not large, so you can directly add it to the code just like that. (For a particular task, you may opt for another way of <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Overview\" target=\"_blank\" rel=\"nofollow\">working with data<\/a>, of course.)<\/p>\n<pre><code class=\"javascript\">const data = [\r\n  {from: 'First Class', to: 'Child', value: 6},\r\n  {from: 'Second Class', to: 'Child', value: 24},\r\n  {from: 'Third Class', to: 'Child', value: 79},\r\n  {from: 'Crew', to: 'Child', value: 0},\r\n  {from: 'First Class', to: 'Adult', value: 319},\r\n  {from: 'Second Class', to: 'Adult', value: 261},\r\n  {from: 'Third Class', to: 'Adult', value: 627},\r\n  {from: 'Crew', to: 'Adult', value: 885},\r\n  {from: 'Child', to: 'Female', value: 45},\r\n  {from: 'Child', to: 'Male', value: 64},\r\n  {from: 'Adult', to: 'Female', value: 425},\r\n  {from: 'Adult', to: 'Male', value: 1667},\r\n  {from: 'Female', to: 'Survived', value: 344},\r\n  {from: 'Female', to: 'Perished', value: 126},\r\n  {from: 'Male', to: 'Survived', value: 367},\r\n  {from: 'Male', to: 'Perished', value: 1364},\r\n]<\/code><\/pre>\n<p>That\u2019s it, everybody is on board, and now it\u2019s time to set sail by writing a few lines of JS charting code!<\/p>\n<h3>4. Write some JS code<\/h3>\n<p>It may feel overwhelming to write code if you do not have much experience doing that. But for an elegant Sankey diagram, some very simple basic code is more than enough.<\/p>\n<p>Before anything else, add the <code>anychart.onDocumentReady()<\/code> function enclosing all the code, which ensures that everything in it will only run once the page is ready. The first thing to add inside is the data.<\/p>\n<pre><code class=\"javascript\">anychart.onDocumentReady(function () {\r\n\r\n  \/\/ add data\r\n  const data = [\r\n    {from: 'First Class', to: 'Child', value: 6},\r\n    {from: 'Second Class', to: 'Child', value: 24},\r\n    {from: 'Third Class', to: 'Child', value: 79},\r\n    {from: 'Crew', to: 'Child', value: 0},\r\n    {from: 'First Class', to: 'Adult', value: 319},\r\n    {from: 'Second Class', to: 'Adult', value: 261},\r\n    {from: 'Third Class', to: 'Adult', value: 627},\r\n    {from: 'Crew', to: 'Adult', value: 885},\r\n    {from: 'Child', to: 'Female', value: 45},\r\n    {from: 'Child', to: 'Male', value: 64},\r\n    {from: 'Adult', to: 'Female', value: 425},\r\n    {from: 'Adult', to: 'Male', value: 1667},\r\n    {from: 'Female', to: 'Survived', value: 344},\r\n    {from: 'Female', to: 'Perished', value: 126},\r\n    {from: 'Male', to: 'Survived', value: 367},\r\n    {from: 'Male', to: 'Perished', value: 1364},\r\n  ]\r\n\r\n  \/\/ everything else goes here\r\n\t\r\n});<\/code><\/pre>\n<p>Now, create a Sankey diagram instance using the built-in charting function and load the data.<\/p>\n<pre><code class=\"javascript\">let chart = anychart.sankey();\r\nchart.data(data);<\/code><\/pre>\n<p>A bit of padding will make sure labels do not get cut off, and a chart title is always helpful.<\/p>\n<pre><code class=\"javascript\">chart.padding(20, 40);  \r\nchart.title('Titanic Survivors');<\/code><\/pre>\n<p>Lastly, just reference the container element to show where the Sankey chart needs to be displayed and draw the resulting visualization.<\/p>\n<pre><code class=\"javascript\">chart.container('container');\r\nchart.draw();<\/code><\/pre>\n<p>Voil\u00e0! A fantastic and functional JavaScript-based Sankey diagram is all ready!<\/p>\n<p><a href=\"https:\/\/playground.anychart.com\/H7EhB3jq\/\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-basic.png\" alt=\"A basic Sankey diagram built with JavaScript\" width=\"100%\" class=\"alignnone size-full wp-image-15013\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-basic.png 1210w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-basic-300x160.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-basic-768x411.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-basic-1024x548.png 1024w\" sizes=\"(max-width: 1210px) 100vw, 1210px\" \/><\/a><\/p>\n<p>Take a look at this initial JS Sankey chart on <a href=\"https:\/\/playground.anychart.com\/H7EhB3jq\/\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a> with the full JS\/CSS\/HTML code (also provided below for your convenience).<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Sankey Diagram&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-sankey.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;  \r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add data\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const data = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"First Class\", to: \"Child\", value: 6},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Second Class\", to: \"Child\", value: 24},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Third Class\", to: \"Child\", value: 79},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Crew\", to: \"Child\", value: 0},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"First Class\", to: \"Adult\", value: 319},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Second Class\", to: \"Adult\", value: 261},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Third Class\", to: \"Adult\", value: 627},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Crew\", to: \"Adult\", value: 885},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Child\", to: \"Female\", value: 45},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Child\", to: \"Male\", value: 64},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Adult\", to: \"Female\", value: 425},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Adult\", to: \"Male\", value: 1667},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Female\", to: \"Survived\", value: 344},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Female\", to: \"Perished\", value: 126},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Male\", to: \"Survived\", value: 367},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Male\", to: \"Perished\", value: 1364}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a sankey diagram instance\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0let chart = anychart.sankey();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ load the data to the sankey diagram instance\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.data(data);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart's padding\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.padding(20, 40);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a title\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.title('Titanic Survivors');\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart container id\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ draw the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Customizing JavaScript Sankey Diagram<\/h2>\n<p>A huge advantage of using a robust JS charting library is the ease with which the initial data visualization is created and the flexibility for further customizations. Let\u2019s see how you can enhance the Sankey diagram\u2019s capabilities and tweak its appearance with some simple modifications.<\/p>\n<h3>1. Color Palette<\/h3>\n<p>To start with, why don\u2019t you add colors that look more intuitive than the default ones? You can create your own color palette by simply listing the colors that you want. Be careful about the sequence when you add the colors.<\/p>\n<pre><code class=\"javascript\">chart.palette([\r\n  \"#f5dc50\",\r\n  \"#e1a03c\",\r\n  \"#c87d5a\",\r\n  \"#fff0c8\",\r\n  \"#aa96b4\",\r\n  \"#6e5a7d\",\r\n  \"#e19196\",\r\n  \"#419bd2\",\r\n  \"#46afaa\",\r\n  \"#5a5050\"\r\n]);<\/code><\/pre>\n<h3>2. Nodes<\/h3>\n<p>Now that you have got a personalized color palette, let\u2019s increase the width of the nodes to make them more prominent. With larger nodes, you can also make greater padding between them.<\/p>\n<pre><code class=\"javascript\">chart.nodeWidth(\"40%\");\r\nchart.nodePadding(30);<\/code><\/pre>\n<p>Larger labels will likely look better as well. Plus, for each node, you can display the corresponding values from the data and make use of HTML to format the text.<\/p>\n<pre><code class=\"javascript\">chart.node().normal().labels().fontSize(14);\r\nchart.node().labels().useHtml(true);\r\nchart\r\n  .node()\r\n  .labels()\r\n  .format(\"&lt;span style='font-weight:bold'&gt;{%name}&lt;\/span&gt;&lt;br&gt;{%value}\");<\/code><\/pre>\n<p><a href=\"https:\/\/playground.anychart.com\/2NjCcNFk\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-customized.png\" alt=\"A customized Sankey chart created  using JavaScript\" width=\"100%\" class=\"alignnone size-full wp-image-15012\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-customized.png 1210w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-customized-300x160.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-customized-768x411.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-customized-1024x548.png 1024w\" sizes=\"(max-width: 1210px) 100vw, 1210px\" \/><\/a><\/p>\n<p>Take a look at the code for this customized JavaScript-based Sankey diagram on <a href=\"https:\/\/playground.anychart.com\/2NjCcNFk\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<h3>3. Links<\/h3>\n<p>Now it\u2019s time to enhance the look of the links. Let\u2019s color them with the same shades as their source nodes. In addition, the links can appear slightly darker when they are hovered over with the mouse.<\/p>\n<pre><code class=\"javascript\">chart.flow({\r\n  normal: {\r\n    fill: function () {\r\n      return anychart.color.lighten(this.sourceColor, 0.5) + \" \" + 0.3;\r\n    }\r\n  },\r\n  hovered: {\r\n    fill: function () {\r\n      return this.sourceColor + \" \" + 0.8;\r\n    }\r\n  }\r\n});<\/code><\/pre>\n<p>Hovering over a node or a link triggers a tooltip that does not even need changes as it is very informative and looks pretty fine by default.<\/p>\n<h3>4. Title<\/h3>\n<p>For the final customization, let\u2019s apply HTML-based formatting to make the title stand out and add a subtitle shedding more light on exactly what the Sankey diagram visualizes.<\/p>\n<pre><code class=\"javascript\">chart\r\n\u00a0\u00a0.title()\r\n\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0.text(\r\n\u00a0\u00a0\u00a0\u00a0'&lt;span style = \"color: #2b2b2b; font-size:20px;\"&gt;Titanic Survivors&lt;\/span&gt;' +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'&lt;br\/&gt;&lt;span style=\"color:#00bfa5; font-size: 16px;\"&gt;(by gender, age, ticket class)&lt;\/span&gt;'\r\n\u00a0\u00a0);<\/code><\/pre>\n<p>That\u2019s all! Now the Sankey diagram is looking so very personalized and engaging, isn\u2019t it?<\/p>\n<p><a href=\"https:\/\/playground.anychart.com\/fiKvNzuZ\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-final.png\" alt=\"The final Sankey diagram (JavaScript HTML5)\" width=\"100%\" class=\"alignnone size-full wp-image-15011\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-final.png 1210w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-final-300x160.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-final-768x411.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-final-1024x548.png 1024w\" sizes=\"(max-width: 1210px) 100vw, 1210px\" \/><\/a><\/p>\n<p>Check out the final code for the interactive JavaScript Sankey diagram below and have fun playing with it further on <a href=\"https:\/\/playground.anychart.com\/fiKvNzuZ\" target=\"_blank\" rel=\"nofollow\">AnyChart Playground<\/a>.<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n\u00a0\u00a0&lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;title&gt;JavaScript Sankey Diagram&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-core.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.11.0\/js\/anychart-sankey.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;style type=\"text\/css\"&gt;      \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0html, body, #container { \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width: 100%; height: 100%; margin: 0; padding: 0; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \r\n\u00a0\u00a0\u00a0\u00a0&lt;\/style&gt;\r\n\u00a0\u00a0&lt;\/head&gt;\r\n\u00a0\u00a0&lt;body&gt;  \r\n\u00a0\u00a0\u00a0\u00a0&lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n\u00a0\u00a0\u00a0\u00a0&lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0anychart.onDocumentReady(function () {\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add data\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const data = [\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"First Class\", to: \"Child\", value: 6},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Second Class\", to: \"Child\", value: 24},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Third Class\", to: \"Child\", value: 79},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Crew\", to: \"Child\", value: 0},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"First Class\", to: \"Adult\", value: 319},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Second Class\", to: \"Adult\", value: 261},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Third Class\", to: \"Adult\", value: 627},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Crew\", to: \"Adult\", value: 885},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Child\", to: \"Female\", value: 45},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Child\", to: \"Male\", value: 64},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Adult\", to: \"Female\", value: 425},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Adult\", to: \"Male\", value: 1667},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Female\", to: \"Survived\", value: 344},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Female\", to: \"Perished\", value: 126},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Male\", to: \"Survived\", value: 367},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{from: \"Male\", to: \"Perished\", value: 1364}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0];\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ create a sankey diagram instance\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0let chart = anychart.sankey();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ load the data to the sankey diagram instance\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.data(data);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart's padding\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.padding(20, 40);\r\n\r\n      \u00a0\u00a0\/\/ configure a custom color palette\r\n      \u00a0\u00a0chart.palette([\r\n      \u00a0\u00a0\u00a0\u00a0\"#f5dc50\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#e1a03c\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#c87d5a\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#fff0c8\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#aa96b4\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#6e5a7d\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#e19196\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#419bd2\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#46afaa\",\r\n      \u00a0\u00a0\u00a0\u00a0\"#5a5050\"\r\n      \u00a0\u00a0]);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ customize the nodes:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the width\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.nodeWidth(\"40%\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the padding\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.nodePadding(30);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ customize the labels\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.node().normal().labels().fontSize(14);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.node().labels().useHtml(true);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.node()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.labels()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.format(\"&lt;span style='font-weight:bold'&gt;{%name}&lt;\/span&gt;&lt;br&gt;{%value}\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ customize the links\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.flow({\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0normal: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fill: function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return anychart.color.lighten(this.sourceColor, 0.5) + \" \" + 0.3;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0hovered: {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fill: function () {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return this.sourceColor + \" \" + 0.8;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ add a title and customize it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.title()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.enabled(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.useHtml(true)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.text(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'&lt;span style = \"color: #2b2b2b; font-size:20px;\"&gt;Titanic Survivors&lt;\/span&gt;' +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'&lt;br\/&gt;&lt;span style=\"color:#00bfa5; font-size: 16px;\"&gt;(by gender, age, ticket class)&lt;\/span&gt;'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ set the chart container id\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.container(\"container\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ draw the chart\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0chart.draw();\r\n  \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/script&gt;\r\n\u00a0\u00a0&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Sankey is such a fascinating chart type. And creating a beautiful one is so very easy!<\/p>\n<p>Actually, this is just the tip of the iceberg, so go on and take a look at more <a href=\"https:\/\/www.anychart.com\/products\/anychart\/gallery\/Sankey_Diagram\">examples of Sankey diagrams<\/a> and see the <a href=\"https:\/\/docs.anychart.com\/Basic_Charts\/Sankey_Diagram\" target=\"_blank\" rel=\"nofollow\">Sankey chart documentation<\/a> to learn how to do something else about them. Also, feel free to check out <a href=\"https:\/\/docs.anychart.com\/Quick_Start\/Supported_Charts_Types\" target=\"_blank\" rel=\"nofollow\">other chart types<\/a>.<\/p>\n<p>Please get in touch with any queries or suggestions.<\/p>\n<hr \/>\n<p><em>The team of AnyChart thanks data designer Shachee Swadia for creating this great Sankey diagramming tutorial.<\/em><\/p>\n<p><em>If you want to write a cool guest post, please send your ideas to our <a href=\"https:\/\/www.anychart.com\/support\/\">Support Team<\/a>.<\/em><\/p>\n<p><em>Check out more <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JavaScript charting tutorials<\/a> on our blog.<\/em><\/p>\n<hr \/>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Would you like to learn how to quickly create a really cool chart called a Sankey diagram? You\u2019re in the right place! Together, we will build an elegant Sankey chart using JavaScript, and then you\u2019ll be able to produce such data visualizations by yourself with no hassle at all. Depicting the flow of values from [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,23,13,279,4],"tags":[619,618,53,289,3173,260,1758,3149,284,127,166,258,471,266,620,1292,880,806,1759,3352,509,2220,54,1389,1760,2757,256,3377,1111,744,844,165,313,1370,774,179,3369,2223,1498,3376,805,3142,91,1762,2013,2014,32,55,1335,144,2979,167,146,152,2949,151,36,907,141,249,3111,81,57,1238,58,65,56,101,1022,1024,415,3375,1023,459,3099,30,3374,172,807,808,954,3100,745,2015,2816,1763,804],"class_list":["post-14973","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-analysis","tag-analytics","tag-anychart","tag-api","tag-app-development","tag-best-data-visualization-examples","tag-chart-design","tag-chart-development","tag-chart-examples","tag-chart-types","tag-charting","tag-charts","tag-data-analysis","tag-data-analytics","tag-data-analytics-examples","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-design","tag-data-graphic","tag-data-graphics","tag-data-visual","tag-data-visualization","tag-data-visualization-best-pracices","tag-data-visualization-design","tag-data-visualization-development","tag-data-visualization-examples","tag-data-visualization-guide","tag-data-visualization-practice","tag-data-visualization-techniques","tag-data-visualization-tutorial","tag-data-visualizations","tag-data-visuals","tag-data-viz-examples","tag-dataviz-examples","tag-design","tag-developers","tag-diagrams","tag-example","tag-flow-visualization","tag-front-end-development","tag-graphic","tag-graphics","tag-guest-post","tag-html","tag-html-charts","tag-html5","tag-html5-charts","tag-infographic","tag-infographics","tag-information-graphics","tag-interactive-charts","tag-interactive-data-visualization","tag-interactive-infographic","tag-interactive-infographics","tag-interactive-visualizations","tag-javascript","tag-javascript-chart-tutorial","tag-javascript-charting","tag-javascript-charting-api","tag-javascript-charting-features","tag-javascript-charting-library","tag-javascript-charts","tag-javascript-graph","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-graphics","tag-sankey-chart","tag-sankey-charts","tag-sankey-diagram","tag-sankey-diagramming","tag-sankey-diagrams","tag-statistics","tag-storytelling-examples","tag-tips-and-tricks","tag-titanic","tag-tutorial","tag-visual-analysis","tag-visual-analytics","tag-visual-data-analytics","tag-visual-storytelling-examples","tag-visualization-techniques","tag-web-charts","tag-web-design","tag-web-developers","tag-web-development","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sankey Diagram &amp; How To Create It with JavaScript<\/title>\n<meta name=\"description\" content=\"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic&#039;s passengers by gender, age &amp; ticket class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Sankey Diagram (with JavaScript)\" \/>\n<meta property=\"og:description\" content=\"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic&#039;s passengers by gender, age &amp; ticket class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-25T14:32:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:11:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-social.png\" \/>\n<meta name=\"author\" content=\"Shachee Swadia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to Create Sankey Diagram (with JavaScript)\" \/>\n<meta name=\"twitter:description\" content=\"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic&#039;s passengers by gender, age &amp; ticket class.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-social.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shachee Swadia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\"},\"author\":{\"name\":\"Shachee Swadia\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"headline\":\"How to Create Sankey Diagram (with JavaScript)\",\"datePublished\":\"2022-05-25T14:32:13+00:00\",\"dateModified\":\"2022-08-13T11:11:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\"},\"wordCount\":1113,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png\",\"keywords\":[\"analysis\",\"analytics\",\"AnyChart\",\"api\",\"app development\",\"best data visualization examples\",\"chart design\",\"chart development\",\"chart examples\",\"chart types\",\"charting\",\"charts\",\"data analysis\",\"data analytics\",\"data analytics examples\",\"data chart\",\"data charting\",\"data charts\",\"data design\",\"data graphic\",\"data graphics\",\"data visual\",\"Data Visualization\",\"data visualization best practices\",\"data visualization design\",\"data visualization development\",\"data visualization examples\",\"data visualization guide\",\"data visualization practice\",\"data visualization techniques\",\"data visualization tutorial\",\"data visualizations\",\"data visuals\",\"data viz examples\",\"dataviz examples\",\"design\",\"developers\",\"diagrams\",\"example\",\"flow visualization\",\"front-end development\",\"graphic\",\"graphics\",\"guest post\",\"HTML\",\"HTML charts\",\"HTML5\",\"html5 charts\",\"infographic\",\"infographics\",\"information graphics\",\"interactive charts\",\"interactive data visualization\",\"interactive infographic\",\"interactive infographics\",\"interactive visualizations\",\"JavaScript\",\"javascript chart tutorial\",\"javascript charting\",\"javascript charting api\",\"JavaScript charting features\",\"JavaScript charting library\",\"javascript charts\",\"javascript graph\",\"js chart\",\"js charting\",\"js charts\",\"JS graphics\",\"Sankey chart\",\"Sankey charts\",\"Sankey Diagram\",\"Sankey diagramming\",\"Sankey diagrams\",\"statistics\",\"storytelling examples\",\"Tips and tricks\",\"Titanic\",\"tutorial\",\"visual analysis\",\"visual analytics\",\"visual data analytics\",\"visual storytelling examples\",\"visualization techniques\",\"web charts\",\"web design\",\"web developers\",\"web development\"],\"articleSection\":[\"AnyChart Charting Component\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\",\"name\":\"Sankey Diagram & How To Create It with JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png\",\"datePublished\":\"2022-05-25T14:32:13+00:00\",\"dateModified\":\"2022-08-13T11:11:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\"},\"description\":\"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic's passengers by gender, age & ticket class.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png\",\"width\":1650,\"height\":917},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Sankey Diagram (with JavaScript)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51\",\"name\":\"Shachee Swadia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g\",\"caption\":\"Shachee Swadia\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sankey Diagram & How To Create It with JavaScript","description":"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic's passengers by gender, age & ticket class.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Sankey Diagram (with JavaScript)","og_description":"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic's passengers by gender, age & ticket class.","og_url":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2022-05-25T14:32:13+00:00","article_modified_time":"2022-08-13T11:11:27+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-social.png","type":"","width":"","height":""}],"author":"Shachee Swadia","twitter_card":"summary_large_image","twitter_title":"How to Create Sankey Diagram (with JavaScript)","twitter_description":"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic's passengers by gender, age & ticket class.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart-social.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Shachee Swadia","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/"},"author":{"name":"Shachee Swadia","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"headline":"How to Create Sankey Diagram (with JavaScript)","datePublished":"2022-05-25T14:32:13+00:00","dateModified":"2022-08-13T11:11:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/"},"wordCount":1113,"commentCount":0,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png","keywords":["analysis","analytics","AnyChart","api","app development","best data visualization examples","chart design","chart development","chart examples","chart types","charting","charts","data analysis","data analytics","data analytics examples","data chart","data charting","data charts","data design","data graphic","data graphics","data visual","Data Visualization","data visualization best practices","data visualization design","data visualization development","data visualization examples","data visualization guide","data visualization practice","data visualization techniques","data visualization tutorial","data visualizations","data visuals","data viz examples","dataviz examples","design","developers","diagrams","example","flow visualization","front-end development","graphic","graphics","guest post","HTML","HTML charts","HTML5","html5 charts","infographic","infographics","information graphics","interactive charts","interactive data visualization","interactive infographic","interactive infographics","interactive visualizations","JavaScript","javascript chart tutorial","javascript charting","javascript charting api","JavaScript charting features","JavaScript charting library","javascript charts","javascript graph","js chart","js charting","js charts","JS graphics","Sankey chart","Sankey charts","Sankey Diagram","Sankey diagramming","Sankey diagrams","statistics","storytelling examples","Tips and tricks","Titanic","tutorial","visual analysis","visual analytics","visual data analytics","visual storytelling examples","visualization techniques","web charts","web design","web developers","web development"],"articleSection":["AnyChart Charting Component","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/","url":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/","name":"Sankey Diagram & How To Create It with JavaScript","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png","datePublished":"2022-05-25T14:32:13+00:00","dateModified":"2022-08-13T11:11:27+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51"},"description":"Learn what a Sankey diagram is, how to build one using JavaScript, and what happened with the Titanic's passengers by gender, age & ticket class.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2022\/05\/sankey-diagram-chart.png","width":1650,"height":917},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2022\/05\/25\/sankey-diagram-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Sankey Diagram (with JavaScript)"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/273255f98371177b5ac1f4775610bb51","name":"Shachee Swadia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50ebd5c61e4e46e052898a5ddbcef5996666132cf07c614be4725f028ec7eae3?s=96&r=g","caption":"Shachee Swadia"},"url":"https:\/\/www.anychart.com\/blog\/author\/shachee-swadia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=14973"}],"version-history":[{"count":23,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14973\/revisions"}],"predecessor-version":[{"id":15529,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/14973\/revisions\/15529"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=14973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=14973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=14973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}