なぜこれでキャンバス上のグラフが消えないのかが知りたいです。clearRectが上手く動いていないです。
html
1<!DOCTYPE html> 2<html lang="en"> 3 4<head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>Document</title> 9 <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" 10 integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" 11 crossorigin="anonymous"></script> 12</head> 13 14<body> 15 <canvas id="canvas"></canvas> 16 17 <script> 18 var ctx = document.getElementById('canvas') 19 var myChart = new Chart(ctx, { 20 type: 'line', 21 data: { 22 labels: [ 23 'Sunday', 24 'Monday', 25 'Tuesday', 26 'Wednesday', 27 'Thursday', 28 'Friday', 29 'Saturday' 30 ], 31 datasets: [{ 32 data: [ 33 15339, 34 21345, 35 18483, 36 24003, 37 23489, 38 24092, 39 12034 40 ], 41 lineTension: 0, 42 backgroundColor: 'transparent', 43 borderColor: '#007bff', 44 borderWidth: 4, 45 pointBackgroundColor: '#007bff' 46 }] 47 }, 48 options: { 49 scales: { 50 yAxes: [{ 51 ticks: { 52 beginAtZero: false 53 } 54 }] 55 }, 56 legend: { 57 display: false 58 } 59 } 60 }) 61 ctx.clearRect(0, 0, ctx.clientWidth, ctx.clientHeight); 62 </script> 63</body> 64 65</html>
結局、どのように解決とされたのでしょう。
https://teratail.com/help/question-tips#questionTips42
フィードバック願います。

回答1件
あなたの回答
tips
プレビュー