|
@@ -1,9 +1,9 @@
|
|
|
<script lang="ts" setup>
|
|
|
import util from "@tools/util";
|
|
|
+import { ref, toRaw, computed, onMounted, watch } from 'vue';
|
|
|
import * as echarts from 'echarts'
|
|
|
-import { computed, onMounted, watch } from 'vue';
|
|
|
const chartId = 'chart-' + util.newGUID(); //chartId
|
|
|
-let chartIns = null //chart 实例
|
|
|
+const chartIns = ref(null) //chart 实例
|
|
|
const props = defineProps({
|
|
|
xAxis: {
|
|
|
type: Object,
|
|
@@ -27,6 +27,10 @@ const props = defineProps({
|
|
|
title: {
|
|
|
type: String,
|
|
|
required: false
|
|
|
+ },
|
|
|
+ subtext: {
|
|
|
+ type: String,
|
|
|
+ required: false
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -34,68 +38,56 @@ const props = defineProps({
|
|
|
const option = computed({
|
|
|
get() {
|
|
|
return {
|
|
|
- angleAxis: props.xAxis || {
|
|
|
- type: 'category',
|
|
|
- data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
|
+ title: {
|
|
|
+ text: props.title || '',
|
|
|
+ subtext: props.subtext || '',
|
|
|
+ textStyle: {
|
|
|
+ fontSize: util.vh(16),
|
|
|
+ color: "#000",
|
|
|
+ },
|
|
|
+ top: 10,
|
|
|
+ left: 30
|
|
|
},
|
|
|
- // title: props.title ||'',
|
|
|
+ angleAxis: props.xAxis || {},
|
|
|
radiusAxis: {},
|
|
|
- polar: {},
|
|
|
+ polar: {
|
|
|
+ radius: '70%',
|
|
|
+ center: ['60%','50%']
|
|
|
+ },
|
|
|
tooltip: {},
|
|
|
- series: props.series || [
|
|
|
- {
|
|
|
- type: 'bar',
|
|
|
- data: [1, 2, 3, 4, 3, 5, 1],
|
|
|
- coordinateSystem: 'polar',
|
|
|
- name: 'A',
|
|
|
- stack: 'a',
|
|
|
- emphasis: {
|
|
|
- focus: 'series'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'bar',
|
|
|
- data: [2, 4, 6, 1, 3, 2, 1],
|
|
|
- coordinateSystem: 'polar',
|
|
|
- name: 'B',
|
|
|
- stack: 'a',
|
|
|
- emphasis: {
|
|
|
- focus: 'series'
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- type: 'bar',
|
|
|
- data: [1, 2, 3, 4, 1, 2, 5],
|
|
|
- coordinateSystem: 'polar',
|
|
|
- name: 'C',
|
|
|
- stack: 'a',
|
|
|
- emphasis: {
|
|
|
- focus: 'series'
|
|
|
- }
|
|
|
- }
|
|
|
- ],
|
|
|
+ series: props.series || [],
|
|
|
legend: {
|
|
|
show: true,
|
|
|
- // data: ['A', 'B', 'C']
|
|
|
+ orient: 'vertical',
|
|
|
+ left: 30,
|
|
|
+ itemWidth: 16,
|
|
|
+ itemHeight: 10,
|
|
|
+ textStyle: {
|
|
|
+ fontSize: util.vh(10)
|
|
|
+ },
|
|
|
+ top: 'middle',
|
|
|
+ data: ['0-2.5','2.5-5','5-7.5','7.5-10','10-12.5','12.5-15','15-17.5','17.5-20','20-22.5','22.5-25','25-inf']
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
set(val) { }
|
|
|
})
|
|
|
watch(() => option, (newVal, oldVal) => {
|
|
|
- if (chartIns) {
|
|
|
+ if (chartIns.value) {
|
|
|
console.log(newVal)
|
|
|
- chartIns.setOption(newVal)
|
|
|
+ const echartIns = toRaw(chartIns.value)
|
|
|
+ echartIns.setOption(newVal)
|
|
|
}
|
|
|
}, { deep: true })
|
|
|
|
|
|
onMounted(() => {
|
|
|
- chartIns = echarts.init(document.getElementById(chartId))
|
|
|
+ const echartIns = echarts.init(document.getElementById(chartId))
|
|
|
+ chartIns.value = echartIns
|
|
|
console.log(JSON.stringify(option.value))
|
|
|
- chartIns.setOption(option.value)
|
|
|
- console.log(chartIns)
|
|
|
+ echartIns.setOption(option.value)
|
|
|
+ console.log(echartIns)
|
|
|
})
|
|
|
</script>
|
|
|
<template>
|
|
|
- <div :id="chartId" :style="{height: props.height, width: props.width}"></div>
|
|
|
+ <div :id="chartId" :style="{ height: props.height, width: props.width }"></div>
|
|
|
</template>
|