我试图让google gauge指针移动,但它没有移动,我设置了动画配置,因为它假设在var选项中设置,例如duration:1000和easing:’inAndOut’,我在Google Api中是n00b所以为了我的无知尝试.
谁能帮我.
这是我正在使用的tutorial link.代码工作但部分工作,仪表指针应该缓慢移动到它的最大值,但是,在我的情况下,它不会工作.
这是代码.
<html>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization','1',{packages:['gauge']});
google.setonLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label','Value'],['Match',80],]);
var options = {
width: 440,height: 140,greenFrom: 70,greenTo: 100,yellowFrom:50,yellowTo: 70,redFrom:0,redTo: 50,minorTicks: 5,animation:{
duration: 1000,easing: 'inAndOut',},majorTicks : ['0','10','20','30','40','50','60','70','80','90','100']
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div<%=id%>'));
chart.draw(data,options);
clearChart();
}
</script>
</html>
解决方法
事实证明我自己想出了这个,在谷歌论坛
here中有一个很好的答案
诀窍是使用0(或任何最小值)值启动仪表,然后稍后更新值(使用setInterval()或任何其他方法)
肯定有更好的方法来更新价值,而不仅仅是编写一个新数组,但你明白了.
<html>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization',0],options);
clearChart();
// This is new.
setTimeout(function(){
var data = google.visualization.arrayToDataTable([
['Label',]);
chart.draw(data,options);
},200);
}
</script>
</html>