2023-04-14 18:41:05 +08:00

138 lines
3.9 KiB
Vue

<template>
<div class="levelTop">
<canvas class="level" canvas-id="levelTop" id="levelTop" @tap="tap"/>
<!-- <image v-if="levelTopPath" class="level" :src="levelTopPath"></image>-->
</div>
</template>
<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
name: "levelTop",
data() {
return {
width:0,
levelTopPath:''
}
},
props: {
data: {
type: Object,
default: () => {}
}
},
watch: {
data: {
handler(value) {
this.handleCarData(value)
},
immediate: true
}
},
methods: {
tap(e){
uChartsInstance[e.target.id].showToolTip(e,{
formatter: (item, category, index, opts) =>{
return item.name + ' '+ item.data + '%';
}
});
uChartsInstance[e.target.id].touchLegend(e);
},
// 处理传入的数据
handleCarData(value) {
let res = value
this.drawCharts('levelTop', res)
},
drawCharts(id, data) {
const ctx = uni.createCanvasContext(id, this);
let _this = this
let phoneInfo = uni.getStorageSync('phoneInfo')
this.width = phoneInfo.screenWidth - 32
uChartsInstance[id] = new uCharts({
type: "column",
context: ctx,
width: _this.width,
height: 272,
categories: data.categories,
series: data.series,
animation: false,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#CAD0DA","#ACB9CD","#1E80FF", ],
padding: [15, 5, 5, 5],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center',
fontSize:10
},
xAxis: {
disableGrid: true,
axisLineColor:'#F2F2F5',
fontSize:10,
titleOffsetY:5
},
yAxis: {
splitNumber:5,
gridColor:'#F2F2F5',
data: [
{
min: 0,
max: 100,
unit:'%',
axisLineColor:'#F2F2F5'
}
]
},
extra: {
column: {
type: "stack",
width: 20,
activeBgColor: "#000000",
activeBgOpacity: 0.08,
labelPosition: "center"
}
}
});
setTimeout( ()=>{
// this.canvasToTempImage('levelTop')
},2000)
},
canvasToTempImage(id){
uni.canvasToTempFilePath({
canvasId:id,
complete:(res)=>{
if (res.tempFilePath){
uni.getFileSystemManager().readFile({
filePath: res.tempFilePath,
encoding: 'base64',
success: res => {
let base64 = 'data:image/png;base64,' + res.data;
this.levelTopPath = base64
}
})
}
}
},this)
},
}
}
</script>
<style scoped lang="scss">
.levelTop{
width:100%;
margin-top: 12px;
.level{
width: 100%;
height: 252px;
}
}
</style>