✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Imoplement a sankey diagram without including the complete Plotly lib

Hello,

I’m working on an implementation where I need to generate a sankey graph in JS. I looked into adding only the minimum components;

"../node_modules/plotly.js/lib/core.js",
"../node_modules/plotly.js/lib/sankey.js"

But this results in a empty graph with an X & Y axis for some reason. It’s not the implementation of the rest of the code, if I include the complete Plotly library the graph is drawn correctly.

I looked into https://github.com/plotly/plotly.js/blob/master/dist/README.md but sankey is not listed there and none of the bundles seems to include it…

Am I missing something or is this by design and is there no other way to draw these kinds of plots?

Regards,

Wouter

The Sankey module is here -> https://github.com/plotly/plotly.js/blob/master/lib/sankey.js

So,

var Plotly = require('plotly.js/lib/core')
Plotly.register(require('plotly.js/lib/sankey'))
  • a build step using browserify or webpack should work.
1 Like

Thank you, this worked. I got confused since it’s not in any of the index packages.

1 Like

I ran the parameters you can have given. However I’m still getting a blank screen when using the bundled JS.

browserify your_parameters.js > bundle.js

<script src='bundle.js'></script>

Are there any other modules that need to be included for the Sankey Diagram?

For reference my script needs to process data from a JSON file.

Plotly.d3.json('./data.json', function (fig) {

and runs fine when using

<script src='plotly-latest.min.js'></script>