• Home
  • Events
  • About
  • Friday Fun LIII – Sankey Plots

    Aloha everyone,

    Creating charts is really fun…again Thomas Nield(@thomasnield9272) pointed me to a nice chart which is called Sankey chart and again I could not withstand to try my best to implement it in JavaFX.

    To give you an idea on what I’m talking about here is an example of such a Sankey plot…

    Compared to last weeks Circular plots these plots can be multilevel and after searching the web for some hours I figured out that you can find all sorts of Sankey plots which might look completely different…here another example…

    That doesn’t make it easier to implement such a chart and so I’ve started reading about the history of that chart. In the end it turned out that the main purpose of this kind of chart is the visualization of flows where the width of the arrows/lines is shown proportionally to the flow quantity.

    So I had to make a decision which style I should follow and I’ve decided to go with the first visualization of the above pictures. Lucky me there is also a version of the Sankey plots in the Google charts which I took as a template. Here is a screenshot of what I’ve come with…

    This is the more colorful version of the chart but it is also possible to create other versions as you can see here…

    In this version I’ve used different parameters for the width of the items and here also the direction of the flow is indicated by arrows (but I only support one direction anyway).

    To get nice results you have to keep in mind that in my implementation you have to think about how to order the items in the chart when adding it to the control.
    Meaning to say I do not have some hyper smart algorithm that do some fancy automatic sorting of items but you have to use your own brain and think about the chart before you create it. For the example above I’ve added the items exactly in the order as they appear on the chart which would look like follows…

    After that is done you have to define the connections between the items by defining only the outgoing streams for each item. Because that’s a lot for the chart above I will only show you the ones for the first column which will look as follows…

    As mentioned you define the streams that goes from each item to other items with their values.
    After that is done you can setup the chart using the SankeyPlotBuilder as follows…

    And that’s all it takes to create such a chart. Because the chart is again based on the JavaFX Canvas node there is no interactivity at the moment but I’m already working on a little project that will make it possible to have interactivity in the future…so stay tuned 🙂

    Of course the code is available on github as always.

    That’s it for today…so keep coding…

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Leave a Comment

    Time limit is exhausted. Please reload the CAPTCHA.

    css.php