Spaces:
Running
Running
File size: 1,488 Bytes
c43c0f2 |
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 |
<head><meta chartset="utf-8">
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="../js/util.js"></script>
<script type="text/javascript" src="../.debugTemp/wpsjsrpcsdk.js"></script>
<script src="https://cdn.staticfile.org/Chart.js/3.9.1/chart.js"></script>
</head>
<body>
<div id="fr" style="width:600px;height:500px;margin:auto">
<canvas id="myChart" width="400" height="300"></canvas>
</div>
<h3>建议直接复制下方数据粘贴到Sheet1表格A1:E1区域,使用时修改数据源区域B1:E1数值即可。</h3>
<table border="1" align="center"><tr><td>数值</td><td>5</td><td>6</td><td>2</td><td>7</td></tr></table>
<script>
wps.ApiEvent.AddApiEventListener('SheetChange',(x,y)=>{if(x.Name=='Sheet1'){fx()}});
function fx(){
$("#myChart").remove();
$("#fr").append('<canvas id="myChart" width="400" height="300"></canvas>');
var data0=wps.ActiveSheet.Range("B1:E1").Value().flat();
const ctx = document.getElementById('myChart');
new Chart(ctx, {type: 'bar',
data: {labels: ['Red', 'Blue', 'Yellow', 'Green'],
datasets: [{label: '# 票数',data: data0,
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>
|