简体   繁体   English

Javascript Google PieChart动画加载

[英]Javascript google PieChart animation load

I'm doing a Google PieChart and I want the load to have a loading effect like the circle shown on this website. 我正在做一个Google PieChart,我希望加载具有加载效果,就像此网站上显示的圆圈一样。 enter link description here But in this web use another library that is not google. 在此处输入链接描述,但在此网络上使用不是Google的另一个库。 I need to find the solution with google. 我需要找到与谷歌的解决方案。

This is my code : 这是我的代码:

enter code here 

function cargarDonut(idElemento, color){
   google.charts.load("current", {packages:["corechart"]});
   google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Task', 'Hours per Day'],
    ['Work',     11],
    ['Eat',      2],
    ]);

  var options = {
    chartArea:{top:'0%',width:'100%', height:'80%'},
    height: 240,
    backgroundColor: 'transparent',
    pieHole: 0.67,
    legend: 'none',
    pieSliceBorder: 100,
    pieSliceText: 'none',
    slices: {  2: {offset: 1}},

    colors: [ '#797879', color],

  };

  var chart = new 
google.visualization.PieChart(document.getElementById(idElemento));
chart.draw(data, options);


}

}

Here i have craeted a example for you. 在这里,我为您提供了一个例子。 https://jsfiddle.net/wecv3x8r/ https://jsfiddle.net/wecv3x8r/

function cargarDonut(idElemento, color){
   google.charts.load("current", {packages:["corechart"]});
   google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Task', 'Hours per Day'],
    ['Work',     11],
    ['Eat',      2],
    ]);

  var options = {
    chartArea:{top:'0%',width:'100%', height:'80%'},
    height: 240,
    backgroundColor: 'transparent',
    pieHole: 0.67,
    legend: 'none',
    pieSliceBorder: 100,
    pieSliceText: 'none',
    slices: {  2: {offset: 1}},

    colors: [ '#797879', color],

  };

  var chart = new 
google.visualization.PieChart(document.getElementById(idElemento));
chart.draw(data, options);
// initial value
    var percent = 0;
    // start the animation loop
    var handler = setInterval(function(){
        // values increment
        percent += 1;
        // apply new values
        data.setValue(0, 1, percent);
        data.setValue(1, 1, 100 - percent);
        // update the pie
        chart.draw(data, options);
        // check if we have reached the desired value
        if (percent > 74)
            // stop the loop
            clearInterval(handler);
    }, 30);

}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM