highcharts / wps-test /ui /chartjs.html
changxin's picture
Update wps-test/ui/chartjs.html
286f9a0
raw
history blame
1.02 kB
<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>