2

I would like to open a new tab like <a href="http://google.com" target="_blank">Plant 1</a> whenever click on the Chart with Javascript.

Summary:

When you click on Plant 1 in the Chart, a new tab with google.com will appear.

When you click on Tan Thanh in the Chart, a new tab with dell.com will appear.

When you click on Plant 3 in the Chart, a new tab with w3schools.com will appear.

When you click on Plant 4 in the Chart, a new tab with simplion.com will appear.


Demo

HTML:

<div id="chart_div" style="width: 550px; height: 500px;"></div>

Javascript:

google.load("visualization", "1", {
packages: ["corechart"]
});
google.setOnLoadCallback(drawChart);

function drawChart() {
var data = google.visualization.arrayToDataTable([
    ['Year', 'link', 'Sales', 'Expenses'],
    ['Plant 1', 'http://google.com', 1000, 400],
    ['Tan Thanh', 'http://dell.com', 1170, 460],
    ['Plant 3', 'http://w3schools.com/', 660, 1120],
    ['Plant 4', 'http://simplion.com', 1030, 540]
]);

var view = new google.visualization.DataView(data);
view.setColumns([0, 3]);

var options = {
    title: 'Company Performance'
};

var chart = new google.visualization.PieChart(document.getElementById('chart_div'));

chart.draw(view, options);
var selectHandler = function (e) {
    window.location = data.getValue(chart.getSelection()[0]['row'], 1);
}

// Add our selection handler.
google.visualization.events.addListener(chart, 'select', selectHandler);
}
PMay 1903
  • 1,103
  • 3
  • 15
  • 31

1 Answers1

1

Use

window.open( data.getValue(chart.getSelection()[0]['row'], 1), options.title, "height=200,width=200");

Instead of,

window.location = data.getValue(chart.getSelection()[0]['row'], 1);
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
  • That's great. However, I am looking for a new tab appears. According to your method, a new window appears. – PMay 1903 Jun 25 '14 at 08:59
  • 1
    @PMay1903 That's not possible in Js without a hack. see here for more details http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript By the way glad to help..! – Rajaprabhu Aravindasamy Jun 25 '14 at 09:01