更新研判首页和echarts组件

This commit is contained in:
2025-05-19 15:50:38 +08:00
parent 1fafd27208
commit 6555a6d277
7 changed files with 276 additions and 106 deletions

View File

@ -3,6 +3,7 @@
</template>
<script setup>
import * as echarts from "echarts";
import { el } from "element-plus/es/locale.mjs";
import { on } from "element-plus/lib/utils";
import { onMounted, ref, reactive, defineProps, onUnmounted, watch, nextTick } from "vue";
@ -16,6 +17,9 @@ const props = defineProps({
default:{
xData:[],
color:[],
stack:false, //fasle 并排展示 true 堆叠展示
barWidth:'12px',
labelColor:'#fff', //横坐标颜色 - 纵坐标颜色 - 标题颜色
list:[]
}
}
@ -29,23 +33,30 @@ watch(()=>props.data,val=>{
function init (val) {
let color = val.color;
let list = val.list
let total = 0
let series = list.map((item ,idx)=>{
let obj = {
type: "bar",
stack:'total',
name:item.label,
data:item.val,
barGap:'80%',
barWidth: "30px",
itemStyle:{normal: { color: color[idx] }}
barWidth: val.barWidth ? val.barWidth: "12px",
}
if(item.label == '总数'){
obj.stack = ''
obj.z = -1
obj.barGap = '-100%'
obj.label = { normal:{show:true,position:'top',color:'#EB00FF'} }
// 是否渐变
if( Array.isArray(color[idx]) && color[idx].length > 0){
obj.label = { normal:{show:true,position:'top',color:color[idx][0] ? color[idx][0] : '#EB00FF'} }
obj.itemStyle = {
normal: {
color: new echarts.graphic.LinearGradient(0,0,0,1,[{ offset: 0, color: color[idx][0] },{ offset: 1, color: color[idx][1] }],false)
}
}
}else{
obj.itemStyle = {normal: {color: color[idx] ? color[idx] : '#EB00FF'}}
obj.label = { normal:{show:true,position:'top',color:color[idx] ? color[idx] : '#EB00FF'} }
}
// 是否堆叠
if(val.stack) obj.stack = 'total';
return obj;
})
chartFn(series)
@ -55,15 +66,15 @@ function chartFn(series) {
var myChart = echarts.init(document.getElementById(props.echartsId));
var option = {
grid: {
top: "30%",
top: "12%",
right: "2%",
left: "2%",
bottom: "3%",
bottom: "5%",
containLabel:true
},
legend:{
data:props.data.list.map(v=>{return v.label}),
textStyle: { color: "#fff"},
textStyle: { color: props.data.labelColor || "#fff" },
icon:'diamond', //arrow,diamond,roundRect,rect,none,circle
itemWidth:16,
itemHeight:8,
@ -84,7 +95,7 @@ function chartFn(series) {
data:props.data.xData,
axisTick: { show: false },
axisLine: { show: false },
axisLabel: { color: "#fff",magin:20 },
axisLabel: { color: props.data.labelColor || "#fff",magin:20 },
},
yAxis: {
type: "value",
@ -97,7 +108,7 @@ function chartFn(series) {
},
axisTick: { show: false },
axisLine: { show: false },
axisLabel: { color: "#fff" },
axisLabel: { color: props.data.labelColor || "#fff"},
},
series:series
};