DeltaG DeltaG -4 years ago 143
Javascript Question

Hyperlinks when clicking on Google Sankey nodes

Is there a way to open a pdf in a popup window from a given URL when clicking a node in a Google visualization Sankey diagram?

I have a fiddle here with a popup message, but I don't know how to render a page inside that window, nor where to define which image goes with which node in the sankey def'ns.

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', 'X', 5 ],
[ 'A', 'Y', 7 ],
[ 'A', 'Z', 6 ],
[ 'B', 'X', 2 ],
[ 'B', 'Y', 9 ],
[ 'B', 'Z', 4 ]
]);

// Sets chart options.
var options = {
width: 600,
sankey: {
node: {
interactivity: true
}
}
};

// Instantiates and draws our chart, passing in some options.
var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
chart.draw(data, options);
google.visualization.events.addListener(chart, 'select', function() {
var sel = chart.getSelection();
if (sel.length)
var href = "http://www.google.com"

alert('You selected node "' + sel[0].name + '"');
});
}

Answer Source

you could use the switch statement to determine which node was selected

then use window.open to show the pdf, etc...

google.visualization.events.addListener(chart, 'select', function() {
  var sel = chart.getSelection();
  if (sel.length) {
    switch (sel[0].name) {
      case 'A':
        window.open('http://www.bing.com');
        break;

      case 'B':
        window.open('http://www.yahoo.com');
        break;

      default:
        window.open('http://www.google.com');
    }
  }
});

see forked fiddle...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download