如何在Google Visualization饼图[corechart]中获取点击的标签名称?即,您如何使用getSelection()
?
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', '');
data.addRows(6);
data.setValue(0, 0, 'Demographics');
data.setValue(0, 1, 1);
data.setValue(1, 0, 'Behavior');
data.setValue(1, 1, 1);
data.setValue(2, 0, 'Campaign');
data.setValue(2, 1, 1);
data.setValue(3, 0, 'Purchases');
data.setValue(3, 1, 1);
data.setValue(4, 0, 'Social');
data.setValue(4, 1, 1);
data.setValue(5, 0, 'Support');
data.setValue(5, 1, 1);
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 500, height: 500, pieSliceText: 'label', legend: 'none', is3D: true,
colors: ['#000033', '#00004D', '#000066', '#000080', '#333399' , '#00001A'],
});
google.visualization.events.addListener(chart, 'select', selectHandler);
function selectHandler(e) {
alert("Need to get clicked pie slice");
}
}
答案 0 :(得分:0)
google.visualization.events.addListener(chart, 'select', function(e) {
var selection = chart.getSelection();
alert(pieSlice[selection[0].row]);
});