gpt4 book ai didi

javascript - Google 图表启动动画不起作用

转载 作者:行者123 更新时间:2023-11-27 22:43:37 26 4
gpt4 key购买 nike

我正在尝试在启动时为谷歌条形图制作动画。图表出现,但没有动画。我想让图表的条形从零增长到最终值。我将animation.startup设置为true,但它仍然不会动画。我做错了什么?

eh.html:

<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="eh.js"></script>

</head>
<body>
<div id="chart_div"></div>
</body>
</html>

eh.js:

google.charts.load('current', {
packages: ['bar'], callback: drawChart
});


function drawChart() {
var choices = ["Banana", "Apple", "Orange"];
var votes = [1, 2, 3];
var name = "Favorite fruit";
var dataArray = [
['Choice', 'Votes']
];

for (var i = 0; i < choices.length; i++) {
dataArray.push([choices[i], votes[i]]);
}
var data = google.visualization.arrayToDataTable(dataArray);

var options = {
animation:{
duration: 1000,
easing: 'linear',
startup: true
},
vAxis: {minValue:0, maxValue:100000000},
title: "votes",
legend: { position: 'none' },
chart: { title: name,
subtitle: 'popularity by Votes' },
bars: 'horizontal', // Required for Material Bar Charts.
axes: {
x: {
0: { side: 'top', label: 'Votes'} // Top x-axis.
}
},
bar: { groupWidth: "90%" }
};

var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, options);
}

最佳答案

Material 图表不支持动画

请参阅 Supported Modifications 下的有效图表类型

您可以使用选项theme: 'material'来获得接近的外观和感觉

'corechart' 不支持顶部 x 轴

请参阅以下工作片段...

google.charts.load('current', {
callback: function () {
var choices = ["Banana", "Apple", "Orange"];
var votes = [1, 2, 3];
var name = "Favorite fruit";
var dataArray = [
['Choice', 'Votes']
];

for (var i = 0; i < choices.length; i++) {
dataArray.push([choices[i], votes[i]]);
}
var data = google.visualization.arrayToDataTable(dataArray);

var options = {
animation:{
duration: 1000,
easing: 'linear',
startup: true
},
vAxis: {minValue:0, maxValue:100000000},
title: "votes",
legend: { position: 'none' },
title: name + '\n' + 'popularity by Votes',
theme: 'material',
bar: { groupWidth: "90%" }
};

var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
},
packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

关于javascript - Google 图表启动动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38579500/

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