fix: 解决环形组件不会自动更新的问题
This commit is contained in:
parent
de0404705b
commit
48a6b14537
@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<v-chart ref="vChartRef" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize></v-chart>
|
||||
<v-chart :theme="themeColor" :option="option.value" autoresize> </v-chart>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {computed, PropType, reactive, watch} from 'vue'
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import VChart from 'vue-echarts'
|
||||
import { use } from 'echarts/core'
|
||||
import { CanvasRenderer } from 'echarts/renderers'
|
||||
@ -12,14 +12,7 @@ import { mergeTheme } from '@/packages/public/chart'
|
||||
import config, { includes } from './config'
|
||||
import { useChartDataFetch } from '@/hooks'
|
||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||
import { isPreview } from '@/utils'
|
||||
import {
|
||||
DatasetComponent,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
TitleComponent,
|
||||
} from 'echarts/components'
|
||||
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent, TitleComponent } from 'echarts/components'
|
||||
|
||||
const props = defineProps({
|
||||
themeSetting: {
|
||||
@ -36,36 +29,41 @@ const props = defineProps({
|
||||
}
|
||||
})
|
||||
|
||||
use([
|
||||
DatasetComponent,
|
||||
CanvasRenderer,
|
||||
PieChart,
|
||||
GridComponent,
|
||||
TooltipComponent,
|
||||
LegendComponent,
|
||||
TitleComponent
|
||||
])
|
||||
use([DatasetComponent, CanvasRenderer, PieChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent])
|
||||
|
||||
const option = reactive({
|
||||
value: {}
|
||||
})
|
||||
|
||||
const dataHandle = (newData: any) => {
|
||||
const d = parseFloat(`${newData}`) * 100
|
||||
let config = props.chartConfig.option
|
||||
config.title.text = d.toFixed(2) + '%'
|
||||
config.series[0].data[0].value[0] = d
|
||||
config.series[0].data[1].value[0] = 100 - d
|
||||
option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
||||
option.value = props.chartConfig.option
|
||||
}
|
||||
|
||||
// 配置时
|
||||
watch(
|
||||
() => props.chartConfig.option.dataset,
|
||||
(newData) => {
|
||||
// console.log('update:'+newData)
|
||||
const d = parseFloat(`${newData}`) * 100
|
||||
let config = props.chartConfig.option
|
||||
config.title.text = d.toFixed(2) + "%"
|
||||
config.series[0].data[0].value[0] = d
|
||||
config.series[0].data[1].value[0] = 100 - d
|
||||
option.value = mergeTheme(config, props.themeSetting, includes)
|
||||
option.value = config
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
() => props.chartConfig.option.dataset,
|
||||
newData => {
|
||||
dataHandle(newData)
|
||||
},
|
||||
{
|
||||
immediate: true
|
||||
}
|
||||
)
|
||||
|
||||
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
|
||||
// 预览时
|
||||
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: number) => {
|
||||
let d = parseFloat(`${resData}`) * 100
|
||||
// @ts-ignore
|
||||
option.value.title.text = d.toFixed(2) + '%'
|
||||
// @ts-ignore
|
||||
option.value.series[0].data[0].value[0] = d
|
||||
// @ts-ignore
|
||||
option.value.series[0].data[1].value[0] = 100 - d
|
||||
})
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user