gpt4 book ai didi

api - 如何在谷歌图表api中添加链接

转载 作者:行者123 更新时间:2023-12-03 22:50:36 27 4
gpt4 key购买 nike

我可以在 google chart api 中添加链接吗?

例如,

enter image description here

如何添加指向“工作”或“吃饭”的链接?

谢谢!

最佳答案

幸运弗兰克的回答很好,但它只是打印了一个警告框。这是一个更完整的答案。我把链接放在DataTable ,然后我创建一个 DataView所以它们不会传递到图表。

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'link', 'Hours per Day'],
['Work', 'http://www.thefreedictionary.com/work', 11],
['Eat', 'http://www.thefreedictionary.com/eat', 2],
['Commute', 'http://www.thefreedictionary.com/commute', 2],
['Watch TV', 'http://www.thefreedictionary.com/television',2],
['Sleep', 'http://www.thefreedictionary.com/sleep', 7]
]);

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

var options = {
title: 'My Daily Activities'
};

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);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 900px;"></div>
</body>
</html>

顺便说一句,Google Charts API 真的很棒!感谢写这个的人。

关于api - 如何在谷歌图表api中添加链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6205621/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com