Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by name in Sankey chart

Is it possible to sort by name using sankey? For example:

Example: https://jsfiddle.net/Khrys/1s3shf2m/

  google.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'From');
    data.addColumn('string', 'To');
    data.addColumn('number', 'Weight');
    data.addRows([
      [ 'A', 'Mango', 5 ],
      [ 'A', 'Mango', 7 ],
      [ 'A', 'Apple', 6 ],
      [ 'B', 'Coconut', 2 ],
      [ 'B', 'Mango', 9 ],
      [ 'B', 'Pineapple', 4 ]
    ]);

    // Sets chart options.
    var options = {
      width: 600,
    };

    // Instantiates and draws our chart, passing in some options.
    var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
    chart.draw(data, options);
  }

I am expecting a output of the right side to be (from top to bottom): Apple, Coconut, Mango, Pineapple

Thanks

like image 730
Khrys Avatar asked Dec 28 '15 15:12

Khrys


People also ask

How do I sort a Sankey chart?

You can simply drag and drop the bars in the desired sorting order.

How do you analyze a Sankey diagram?

The key to reading and interpreting Sankey Diagrams is remembering that the width is proportional to the quantity represented. In the example below, the audience quickly sees that largest destination for water is terrestrial evaporation, among other features of the hydrologic cycle.

What is a node in a Sankey diagram?

A sankey diagram is a visualization used to depict a flow from one set of values to another. The things being connected are called nodes and the connections are called links.


2 Answers

Set iterations to 0, and the diagram should draw according to the input order of the data.

Example:

var options = {
  height: 400,
  width: 400,
  sankey: {
iterations: 0,
      }

Regards

like image 147
HighlyKiwi Avatar answered Nov 27 '22 01:11

HighlyKiwi


As answered by Daniel from Google itself in https://groups.google.com/forum/#!topic/google-visualization-api/Tsyj8ZQ8IMU

Sorry, we don't have sufficient control over the generated order of the output nodes.

like image 40
Khrys Avatar answered Nov 27 '22 00:11

Khrys