<template> <div :id="id" style="width: 100%; height: 100%"></div> </template> <script> import * as echarts from "echarts"; import { guid } from "@/utils/util"; import { reactive, toRefs, onMounted, watch, nextTick } from "vue"; export default { name: "bar2", props: { data: Object, }, setup(props) { console.log(props, 'uuuuuuuuu') const state = reactive({ id: guid(), chart: null, }); const resizeTheChart = () => { if (state.chart) { state.chart.resize(); } }; const init = () => { let chartDom = echarts.init(document.getElementById(state.id)); chartDom.clear(); let option; var indictedCase = [10, 7, 15, 8, 6, 2, 1, 3]; option = { tooltip: { trigger: "axis", backgroundColor: "#F5F8FA", borderColor: "#143343", axisPointer: { type: "shadow", }, textStyle: { fontSize: 14, fontWeight: 500, color: "#666666" }, formatter(params) { return '<div style="width:110px">' + "<h4>" + "处理设施个数:" + "</h4>" + '<span style="float:left;">' + params[0].name + ":" + "</span>" + '<span style="float:right;">' + params[0].value + "个" + "</span>" + "</div>" } }, legend: { show: false, top: "5%", textStyle: { color: "#fff", }, }, grid: { top: "25%", left: "3%", right: "3%", bottom: "5%", containLabel: true, }, xAxis: { type: "category", axisLabel: { color: "#fff", }, axisLine: { lineStyle: { color: "rgba(45, 60, 92, 1)", width: 1, //这里是为了突出显示加上的 }, }, splitLine: { lineStyle: { color: "rgba(45, 60, 92, 1", width: 1, }, }, data: props.data[0].xdata }, yAxis: { type: "value", axisLabel: { color: "#fff", }, axisLine: { show: true, lineStyle: { color: "rgba(45, 60, 92, 1)", width: 1, //这里是为了突出显示加上的 }, }, splitLine: { lineStyle: { color: "rgba(45, 60, 92, 1", width: 1, }, }, }, series: [ { name: "数量", type: "bar", barWidth: 8, barGap: 0, label: { normal: { show: false, position: "insideRight", }, }, itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [ { offset: 0, color: "rgba(20, 43, 128, 0.2)", }, { offset: 1, color: "rgba(57, 206, 255, 1)", }, ]), }, }, data: props.data[0].ydata }, { name: "数量", type: "bar", barWidth: 8, tooltip: { show: false, }, label: { normal: { show: false, position: "insideRight", }, }, itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [ { offset: 0, color: "rgba(20, 43, 128, 0.2)", }, { offset: 1, color: "rgba(57, 206, 255, 1)", }, ]), }, }, data: props.data[0].ydata }, { name: "数量", type: "pictorialBar", // 长方体顶部四边形 symbol: "diamond", symbolRotate: 0, symbolSize: ["16", "10"], symbolOffset: ["0", "-5"], symbolPosition: "end", z: 3, // 顶部四边形 tooltip: { show: false, }, label: { normal: { show: false, position: "insideRight", }, }, itemStyle: { normal: { color: "rgba(57, 206, 255, 0.9)", }, }, data: props.data[0].ydata }, ], }; option && chartDom.setOption(option, true); state.chart = chartDom; }; watch( () => props.data, (newVal, oldVal) => { init(); } ); onMounted(() => { nextTick(() => { init(); window.addEventListener("resize", resizeTheChart); }) }); return { ...toRefs(state), resizeTheChart, init, }; }, }; </script>