ahyd_DIB/pages/index/components/monthCharts.vue
2023-08-09 18:59:14 +08:00

95 lines
1.9 KiB
Vue

<template>
<view class="main">
<canvas class="month" canvas-id="month" id="month"/>
</view>
</template>
<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
name: "monthCharts",
data(){
return {
}
},
props:{
success:{
type: Number,
default: 0
}
},
watch:{
success:{
handler(value){
console.log('value111',value)
let success = Number(value)>100?100:Number(value)
let error = Number(100 - value)<0?0:Number(100 - value)
let res = {
series:[{
data:[{name:'已完成',value:success},{name:'未完成',value:error}]
}]
}
this.drawCharts('month',res)
}
}
},
methods:{
drawCharts(id,data){
const ctx = uni.createCanvasContext(id, this);
let _this = this
uChartsInstance[id] = new uCharts({
type: "ring",
context: ctx,
width: 68,
height: 68,
series: data.series,
animation: true,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#576EFF","#EBEEF2"],
padding: [5,5,5,5],
dataLabel: false,
enableScroll: false,
legend: {
show: false,
position: "right",
lineHeight: 25
},
title: {
name: _this.success + '%',
fontSize: 10,
color: "#3D57FB"
},
extra: {
ring: {
ringWidth: 10,
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: -90,
labelWidth: 15,
border: false,
borderWidth: 3,
customRadius:34,
borderColor: "#FFFFFF"
}
}
});
},
}
}
</script>
<style lang="scss" scoped>
.main{
width: 100%;
height: 100%;
.month{
width: 136rpx;
height: 136rpx;
}
}
</style>