How Do I Build a Sankey Chart?

How Do I Build a Sankey Chart?

How to Build a Sankey Chart

If you want to analyze navigation patterns in your course, then you can show branching — and even abandonment — with a Sankey chart.

How to create — In an Advanced Graph Query widget, insert code like this…

{ "title": "Course Navigation",
"subtitle": "“Neural Networks and Deep Learning” Interactions",
"filter": {
"object.id": {
"$in": [
"https://www.coursera.org/specializations/deep-learning/1/interactions/1",
"https://www.coursera.org/specializations/deep-learning/1/interactions/2"]}},
"process": [{
"$paths": {
"stepValuePath": "object.definition.description.en-US",
"sessionPath": "context.registration"}}, {
"$pathsToNodes": {
"order": false}}, {
"$sankeyChart": {}}]}


The filter stage uses a logical IN to limit the nodes to the selected objects, which the widget uses as the “value path”. As is typical with Sankey charts in the LRS, the “session path” follows the context registration.


Here’s an example of a Sankey chart widget for navigation between interactions in a lesson.

How to interpret — In the chart above, three times students responded to the “Neural networks" interaction first, then the “Backpropagation” interaction. Six times students responded in the opposite order.
NotesYou can customize this chart by adding MongoDB stages that $match length of branches and $sort last branches. You can also change the style by adding amCharts fields.