每1秒将convasjs甜甜圈图旋转1度

时间:2018-07-07 09:11:05

标签: javascript setinterval

我正在使用convasjs甜甜圈图,如下所示: https://canvasjs.com/docs/charts/chart-options/data/startangle/

<!DOCTYPE HTML>
<html>
<head>
  <script type="text/javascript">
  window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer",
    {
      title:{
      text: "Doughnut rotated by 90 degrees "
      },
      data: [
      {
        type: "doughnut",
        indexLabelPlacement: "outside",
         startAngle: 90,  //vary the angle here.
        dataPoints: [
          { x: 10, y: 71, label: "first" },
          { x: 20, y: 55, label: "second"},
          { x: 30, y: 50, label: "third"},
          { x: 40, y: 125, label: "fourth"},
          { x: 90, y: 14, label: "fifth"}
        ]
      }
      ]
    });

    chart.render();
  }
  </script>
 <script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</head>
<body>
  <div id="chartContainer" style="height: 300px; width: 100%;">
  </div>
</body>
</html>

,要在页面加载后每秒开始旋转1度。可以通过更改startAngle变量来手动旋转它。 问题是如何在页面加载后数秒内自动增加startAngle值。 我也尝试过setinterval函数,但可能有一个错误,但没有成功。 请检查此:

<!DOCTYPE HTML>
<html>
<head>
  <script>

  window.onload = function () {
    var counter = 360;
  setInterval(function() {
    counter--;
    if (counter >= 0) {
      span = document.getElementById("count");
      span.innerHTML = counter;
    }
  }, 1000);
    var chart = new CanvasJS.Chart("chartContainer",
    {
      title:{
      text: "Doughnut rotated by 90 degrees "
      },
      data: [
      {
        type: "doughnut",
        indexLabelPlacement: "outside",
         startAngle: counter,  //vary the angle here.
        dataPoints: [
          { x: 10, y: 71, label: "first" },
          { x: 20, y: 55, label: "second"},
          { x: 30, y: 50, label: "third"},
          { x: 40, y: 125, label: "fourth"},
          { x: 90, y: 14, label: "fifth"}
        ]
      }
      ]
    });

    chart.render();
  }
  </script>

 <script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</head>
<body>
  <span id="count"></span>
  <div id="chartContainer" style="height: 300px; width: 100%;">
  </div>
</body>
</html>

0 个答案:

没有答案