424
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
watch(
|
||||
() => props.list,
|
||||
(val) => {
|
||||
// console.log(val,'88888888888888888')
|
||||
aIndex+=1
|
||||
if(aIndex>=3&&!val.length){
|
||||
condShow.value = 1
|
||||
|
||||
@@ -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
|
||||
condShow.value = 2
|
||||
setTimeout(() => {
|
||||
condShow.value = 2
|
||||
init()
|
||||
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',
|
||||
@@ -79,10 +85,10 @@
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const init = () => {
|
||||
// if (!params) {
|
||||
params = {
|
||||
if (!params.value) {
|
||||
params.value = {
|
||||
legend: {
|
||||
show: true,
|
||||
x: 'center',
|
||||
@@ -91,12 +97,15 @@
|
||||
itemWidth: fitChartSize(12),
|
||||
itemGap: fitChartSize(6),
|
||||
formatter: function (name) {
|
||||
console.log(name,'nnnnnnnnnnnnnnnnnnnnnnnn')
|
||||
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(name){
|
||||
let obj = props.list.find((item) => item.name == name)
|
||||
return '{name|' + name + '} {value|' + obj?.value + '}{value|%}'
|
||||
}
|
||||
|
||||
// if(obj.value){
|
||||
// obj.value?obj.value:0;
|
||||
|
||||
// }
|
||||
|
||||
},
|
||||
textStyle: {
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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:[]
|
||||
|
||||
Reference in New Issue
Block a user