2024-01-04 18:57:17 +08:00

159 lines
4.6 KiB
Vue

<template>
<div class="consumPrefer">
<QiunDataCharts
type="radar"
:opts="opts"
:chartData="res"
:animation="false"
:inScrollView="true"
tooltipFormat="consumPrefer"
/>
<!-- <canvas style="width: 100vw;height: 274px;position: fixed;left: 100vw" class="prefer" canvas-id="prefer" id="prefer" @tap="tap"/>-->
<!-- <image style="width: 100vw;height: 274px;" v-if="preferPath" class="prefer" :src="preferPath"></image>-->
</div>
</template>
<script>
import QiunDataCharts from "../qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue";
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
name: "consumPrefer",
components:{QiunDataCharts},
data() {
return {
width:0,//手机宽度
preferPath:'',//路径
opts:{},
res:{}
}
},
props: {
data: {
type: Object,
default: () => {}
}
},
watch: {
data: {
handler(value) {
this.handleCarData(value)
},
immediate: true
}
},
methods: {
tap(e){
uChartsInstance[e.target.id].touchLegend(e);
},
// 处理传入的数据
handleCarData(value) {
let res = value
this.res = value
this.opts = {
categories: res.categories,
series: res.series,
animation: false,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#1E80FF", "#00C2FF"],
padding: [5, 5, 5, 5],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center'
},
extra: {
radar: {
gridType: "radar",
gridColor: "#CCCCCC",
gridCount: 3,
opacity: 0.2,
max: res.max,
labelShow: true,
border: true
}
}
}
// this.drawCharts('prefer', 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: "radar",
context: ctx,
width: _this.width,
height: 294,
categories: data.categories,
series: data.series,
animation: false,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#1E80FF", "#00C2FF"],
padding: [5, 5, 5, 5],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center'
},
extra: {
radar: {
gridType: "radar",
gridColor: "#CCCCCC",
gridCount: 3,
opacity: 0.2,
max: data.max,
labelShow: true,
border: true
}
}
});
setTimeout( ()=>{
this.canvasToTempImage('prefer')
},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.preferPath = base64
}
})
}
}
},this)
},
}
}
</script>
<style scoped lang="scss">
.consumPrefer{
width: calc(100vw - 32px);
height: 274px;
.prefer{
width: 100%;
height: 100%;
}
}
</style>