微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – Google API:评估动画

我试图让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>

原文地址:https://www.jb51.cc/js/150213.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐