122 lines
3.4 KiB
Vue
122 lines
3.4 KiB
Vue
<template>
|
|
<div class="timePeriodAnalysis">
|
|
<canvas v-if="!timePeriodPath" class="timePeriod" canvas-id="timePeriod" id="timePeriod"/>
|
|
<image class="timePeriod" v-if="timePeriodPath" :src="timePeriodPath"></image>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import uCharts from '@/components/u-charts.js';
|
|
var uChartsInstance = {};
|
|
export default {
|
|
name: "timePeriodAnalysis",
|
|
data() {
|
|
return {
|
|
width:0,
|
|
timePeriodPath:''
|
|
}
|
|
},
|
|
props: {
|
|
data: {
|
|
type: Object,
|
|
default: () => {}
|
|
}
|
|
},
|
|
watch: {
|
|
data: {
|
|
handler(value) {
|
|
console.log('carDatawatch', value)
|
|
this.handleCarData(value)
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
// 处理传入的数据
|
|
handleCarData(value) {
|
|
let res = value
|
|
this.drawCharts('timePeriod', 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: "bubble",
|
|
context: ctx,
|
|
width: _this.width,
|
|
height: 200,
|
|
series: data.series,
|
|
animation: true,
|
|
rotate: false,
|
|
rotateLock: false,
|
|
background: "#FFFFFF",
|
|
color: ["#C7DFFF"],
|
|
padding: [15, 10, 5, 5],
|
|
dataLabel: false,
|
|
enableScroll: false,
|
|
xAxis: {
|
|
disableGrid: true,
|
|
gridType: "dash",
|
|
splitNumber: 6,
|
|
boundaryGap: "justify",
|
|
min: 0,
|
|
max: 24
|
|
},
|
|
yAxis: {
|
|
disableGrid: false,
|
|
gridType: "dash",
|
|
data: [
|
|
{
|
|
min: 0,
|
|
max: 50
|
|
}
|
|
]
|
|
},
|
|
legend: {
|
|
show: false,
|
|
position: "bottom",
|
|
lineHeight: 25,
|
|
float: 'center',
|
|
},
|
|
extra: {
|
|
bubble: {
|
|
border: 2,
|
|
opacity: 0.5
|
|
}
|
|
}
|
|
});
|
|
setTimeout( ()=>{
|
|
this.canvasToTempImage('timePeriod')
|
|
},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.timePeriodPath = base64
|
|
}
|
|
})
|
|
}
|
|
}
|
|
},this)
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.timePeriodAnalysis{
|
|
width: 100%;
|
|
.timePeriod{
|
|
width: 100%;
|
|
height: 200px;
|
|
}
|
|
}
|
|
</style> |