From 9ad80a31337e3f22b8e66344b13afacdb52c028b Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 29 七月 2025 16:03:29 +0800 Subject: [PATCH] 1.能源管理-开发、联调 --- src/components/Echarts/echarts.vue | 40 +++++++++++++++++++++++----------------- 1 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/components/Echarts/echarts.vue b/src/components/Echarts/echarts.vue index 4601e41..2c51ace 100644 --- a/src/components/Echarts/echarts.vue +++ b/src/components/Echarts/echarts.vue @@ -70,7 +70,15 @@ maskColor: 'rgba(255, 255, 255, 0.8)', zlevel: 0 }) - } + }, + color: { + type: Array, + default: () => [] + }, + option: { + type: Object, + default: () => ({}) + }, }) import { watch } from 'vue' @@ -83,28 +91,26 @@ function generateChart(option) { const copiedOption = JSON.parse(JSON.stringify(option)) // 鉁� 娣辨嫹璐� - // if (copiedOption.series && copiedOption.series.length > 0) { - // copiedOption.series.forEach((s, index) => { - // if (s.type === 'line') { - // s.itemStyle = { - // color: props.lineColors[index] || props.lineColors[0] - // } - // s.lineStyle = { - // color: props.lineColors[index] || props.lineColors[0] - // } - // } else if (s.type === 'bar') { - // s.itemStyle = { - // color: props.barColors[index] || props.barColors[0] - // } - // } - // }) - // } + if (copiedOption.series && copiedOption.series.length > 0) { + copiedOption.series.forEach((s, index) => { + if (s.type === 'line' && props.lineColors.length) { + s.itemStyle = s.itemStyle || {} + s.lineStyle = s.lineStyle || {} + s.itemStyle.color = props.lineColors[index] || props.lineColors[0] + s.lineStyle.color = props.lineColors[index] || props.lineColors[0] + } else if (s.type === 'bar' && props.barColors.length) { + s.itemStyle = s.itemStyle || {} + s.itemStyle.color = props.barColors[index] || props.barColors[0] + } + }) + } chartInstance.setOption(copiedOption) } function renderChart() { const option = { + color: props.color.length ? props.color : undefined, backgroundColor: props.options.backgroundColor || '#fff', xAxis: props.xAxis, yAxis: props.yAxis, -- Gitblit v1.9.3