gpt4 book ai didi

javascript - 结合气泡图和桑基图 Google Charts

转载 作者:行者123 更新时间:2023-11-28 01:28:23 26 4
gpt4 key购买 nike

我正在尝试将 Google Charts 中的气泡图和桑基图元素结合起来,但很难让它们显示在页面上。 (这是来自 Google 的示例代码)。当我隔离气泡图或桑基图的代码时,它们可以工作 - 但将它们放在一起,什么也没有发生。我确保设置了唯一的变量名称,但不确定我还缺少什么。而且我确实没有编码经验,只是对 Python 有一定的了解,所以我可能完全过于简单化了。感谢您的帮助!

<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.load("visualization", "1.1", {packages:["sankey"]});

google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.arrayToDataTable([
['ID', 'Life Expectancy', 'Fertility Rate', 'Region', 'Population'],
['CAN', 80.66, 1.67, 'North America', 33739900],
['DEU', 79.84, 1.36, 'Europe', 81902307],
['DNK', 78.6, 1.84, 'Europe', 5523095],
['EGY', 72.73, 2.78, 'Middle East', 79716203],
['GBR', 80.05, 2, 'Europe', 61801570],
['IRN', 72.49, 1.7, 'Middle East', 73137148],
['IRQ', 68.09, 4.77, 'Middle East', 31090763],
['ISR', 81.55, 2.96, 'Middle East', 7485600],
['RUS', 68.6, 1.54, 'Europe', 141850000],
['USA', 78.09, 2.05, 'North America', 307007000]
]);

var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'From');
data2.addColumn('string', 'To');
data2.addColumn('number', 'Weight');
data2.addRows([
[ 'A', 'X', 5 ],
[ 'A', 'Y', 7 ],
[ 'A', 'Z', 6 ],
[ 'B', 'X', 2 ],
[ 'B', 'Y', 9 ],
[ 'B', 'Z', 4 ],
]);

var options = {
title: 'Correlation between life expectancy, fertility rate and population of some world countries (2010)',
hAxis: {title: 'Life Expectancy'},
vAxis: {title: 'Fertility Rate'},
bubble: {textStyle: {fontSize: 11}}
};

var options2 = {
width: 600,
};

var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
chart.draw(data, options);

var chart2 = new google.visualization.Sankey(document.getElementById('sankey_basic'));
chart2.draw(data2, options2);
}
</script>
</head>
<body>
<div id="sankey_basic" style="width: 900px; height: 300px;"></div>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>

最佳答案

使用此代码出现错误

Uncaught TypeError: undefined is not a function 

报告行:

var chart2 = new google.visualization.Sankey(document.getElementById('sankey_basic'));

该错误与未加载包 sankey 相同。

更改线路:

  google.load("visualization", "1.1", {packages:["sankey"]});

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

加载两个图表。

谷歌 sankey docs显示版本 1,一些示例使用版本 1.1,这令人困惑。

关于javascript - 结合气泡图和桑基图 Google Charts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22438240/

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