File size: 1,016 Bytes
286f9a0
717913e
 
 
 
 
 
b3cac79
 
717913e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61849f9
b3cac79
717913e
 
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
<head><meta charset="utf-8">
<script src="https://cdn.staticfile.org/Chart.js/3.9.1/chart.js"></script>
</head>
<body>
<div style="width:600px;height:500px;margin:auto">
<canvas id="myChart" width="400" height="300"></canvas>
</div>
<button onclick="fx()">转为base64资源</button>
<p></p>
<script>
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {type: 'bar',
    data: {labels: ['Red', 'Blue', 'Yellow', 'Green'],
        datasets: [{label: '# 票数',data: [12, 19, 3, 5],
            backgroundColor: ['rgba(255, 99, 132, 0.2)','rgba(54, 162, 235, 0.2)','rgba(255, 206, 86, 0.2)','rgba(75, 192, 192, 0.2)'],
            borderColor: ['rgba(255, 99, 132, 1)','rgba(54, 162, 235, 1)','rgba(255, 206, 86, 1)','rgba(75, 192, 192, 1)'],
            borderWidth: 1}]
    },
    options: {scales: {y: {beginAtZero: true}}}
});
</script>
</body>
<script>
function fx(){
	var a=document.getElementById('myChart').toDataURL();
	document.getElementsByTagName('p')[0].innerText=a
}
</script>