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( watch(
() => props.list, () => props.list,
(val) => { (val) => {
// console.log(val,'88888888888888888')
aIndex+=1 aIndex+=1
if(aIndex>=3&&!val.length){ if(aIndex>=3&&!val.length){
condShow.value = 1 condShow.value = 1

View File

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

View File

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