On load Google LineChart animation

前端 未结 1 1190
梦毁少年i
梦毁少年i 2021-01-15 08:16

I\'m trying to implement loading animation of chart using transition animations by adding rows and refreshing the chart. But it behaves completely differently from what I ex

相关标签:
1条回答
  • 2021-01-15 08:48

    Ok, I've managed to solve that. It's all a matter of using 'animationfinish' That now looks like http://jsfiddle.net/HDu8H/ or

    google.load('visualization', '1', { packages: ['corechart'], callback: function() {
            var data = new google.visualization.DataTable();
            data.addRows(5);
    
            data.addColumn('string', '');
            data.addColumn('number', 'Sales');
            data.addRows(5);
            data.setValue(0, 0, 'Jan');
            data.setValue(1, 0, 'Feb');
            data.setValue(2, 0, 'Mar');
            data.setValue(3, 0, 'Apr');
            data.setValue(4, 0, 'May');
    
            var options = {
                title: 'Sales by months for 2013 year', curveType: 'function',
                "vAxis": { "minValue": "0", "maxValue": 6 }, "hAxis": { "slantedTextAngle": "45", "slantedText": "true" }, "legend": { "position": "top" }, "pointSize": "5",
                animation: { duration: 250 }
            };
            var chart = new google.visualization.LineChart(document.getElementById('test'));
    
            var index = 0;
            var chartData = [ 5, 1, 4, 2, 3 ]
            var drawChart = function() {
                console.log('drawChart index ' + index);
                if (index < chartData.length) {
                    data.setValue(index, 1, chartData[index++]);
                    chart.draw(data, options);
                }
            }
    
            google.visualization.events.addListener(chart, 'animationfinish', drawChart);
            chart.draw(data, options);
            drawChart();
        }});
    
    0 讨论(0)
提交回复
热议问题