This commit is contained in:
duanliang
2025-04-24 21:13:54 +08:00
parent f01789286e
commit 0312549427
3 changed files with 34 additions and 23 deletions

View File

@@ -42,7 +42,6 @@
watch(
() => props.list,
(val) => {
// console.log(val,'88888888888888888')
aIndex+=1
if(aIndex>=3&&!val.length){
condShow.value = 1

View File

@@ -20,7 +20,7 @@
import { useEchart } from '@/hooks/echart'
import styleUtil from '@/utils/styleUtil'
const { id, setOption } = useEchart()
const { id, setOption,clearOption,dispose,chartVal} = useEchart()
let props = defineProps({
list: {
@@ -37,10 +37,11 @@
}
})
let params = null
let params = ref(null)
let condShow = ref(0)
let aIndex = 1
let newList = ref([])
let datas = ref([])
watch(
() => props.list,
(val) => {
@@ -50,9 +51,13 @@
}
if (val.length > 0) {
newList.value = val
setTimeout(() => {
condShow.value = 2
setTimeout(() => {
if(params.value){
dispose()
}
init()
}, 1000)
}
},
@@ -62,8 +67,9 @@
)
const getSeriesData = () => {
console.log(props.list,'props.listprops.listprops.list')
return newList.value.map((item) => {
return props.list.map((item) => {
item.value?item.value:0;
return {
type: 'bar',
@@ -81,8 +87,8 @@
}
const init = () => {
// if (!params) {
params = {
if (!params.value) {
params.value = {
legend: {
show: true,
x: 'center',
@@ -91,13 +97,16 @@
itemWidth: fitChartSize(12),
itemGap: fitChartSize(6),
formatter: function (name) {
console.log(name,'nnnnnnnnnnnnnnnnnnnnnnnn')
if(name){
let obj = props.list.find((item) => item.name == name)
if(obj?.value){
obj.value?obj.value:0;
return '{name|' + name + '} {value|' + obj?.value + '}{value|%}'
}
// if(obj.value){
// obj.value?obj.value:0;
// }
},
textStyle: {
rich: {
@@ -136,12 +145,14 @@
},
series: getSeriesData()
}
let datas = getSeriesData()
// }
// else {
// params.series = getSeriesData()
// }
setOption(params)
}
else {
// dispose()
params.value.series = getSeriesData()
}
setOption(params.value)
}
</script>

View File

@@ -9,12 +9,13 @@ export function useEchart() {
const initChart = () => {
const dom = document.getElementById(id.value)
chart = echarts.init(dom)
chartVal.value = chart
}
const setOption = (params, update = false) => {
initChart()
chart.setOption(params, update)
}
const clearOption = () => {
console.log('clearooooooooooooooooo')
// 将series设置为空数组可以清空图表内容
chart.setOption({
series:[]