1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div> <img src="https://wong-1251253615.cos.ap-shanghai.myqcloud.com/blog/images/2019-03-13/chart.gif" alt=""> </div> <div style="height: 300px;width: 500px"> <canvas id="chart1"></canvas> </div> <script src="js/chart.js"></script> <script> var xData = ['x1','x2','x3','x4','x5','x6','x7','x8','x9','x10'], yData = [13,35,78,100,130,190,240,300,350,400], len = yData.length, count = 0; var myChart = new Chart('chart1',{ type: 'line', data: { labels: xData, datasets:[{ label: '测试', backgroundColor: 'rgba(54, 162, 235, .8)', borderColor: 'deepskyblue', pointBackgroundColor: 'rgba(54, 162, 235, .4)', pointBorderColor: 'translate', data: [] }] }, options: { animation: { duration: 0 }, scales: { yAxes:[{ ticks:{ max: 400 } }] } } }); var timer = setInterval(() => { if(count > len){ clearInterval(timer) } myChart.data.datasets.forEach(function(dataset){ dataset.data.push(yData[count]) }) myChart.update(); count++; },100) </script> </body> </html>
|