<template> <div :id="id" style="width: 100%; height: 100%"></div> </template> <script> import * as echarts from "echarts"; import { guid } from "@/utils/ruoyi"; import { reactive, toRefs, onMounted, watch } from "vue"; export default { name: "detail-cod", props: { data: Object, refresh: Number, }, setup (props) { const allData = reactive({ series: [], legend: [], id: guid(), chart: null, }); const resizeTheChart = () => { if (allData.chart) { allData.chart.resize(); } }; const init = () => { let chartDom = echarts.init(document.getElementById(allData.id)); var option; option = { color: ["#297fe0", "#1ddbc6"], legend: { show: true, // orient: 'vertical', // y: 'top', //延Y轴居中 x: "right", //居右显示 align: "left", //图例控制在左边 icon: "circle", padding: [ 20, // 上 20, // 右 0, // 下 0, // 左 ], itemWidth: 15, itemHeight: 15, itemStyle: { // opacity: 0 // icon: '' }, itemHeight: 15, textStyle: { color: "auto", rich: { another: { fontSize: 28, }, }, fontSize: 14, }, }, tooltip: { trigger: "axis", // formatter: "{b}:{c}件", // formatter: "{b}:{c}", feature: { mark: { show: true }, dataView: { show: true, readOnly: false }, magicType: { show: true, type: ["line", "bar"] }, restore: { show: true }, saveAsImage: { show: true }, }, axisPointer: { type: "cross", textStyle: { color: "#fff", }, }, }, grid: { top: "25%", left: "3%", right: "5%", bottom: "5%", containLabel: true, }, xAxis: [ { type: "category", data: props.data.XAxis, axisPointer: { type: "shadow", }, axisLabel: { show: true, color: "#fff", }, axisLine: { lineStyle: { // color: "#3398DB" }, }, }, ], yAxis: [ { name: "", type: "value", max: props.data.upMax, axisLabel: { show: true, color: "rgba(41, 127, 224)", }, axisLine: { lineStyle: { color: "rgba(41, 127, 224)", }, }, splitLine: { show: true, lineStyle: { color: "rgba(61,91,98,0.8)", }, }, }, { inverse: true, //控制x轴在上方 name: "", max: props.data.dataMax, type: "value", axisLabel: { show: true, color: "#1edac6", }, axisLine: { lineStyle: { color: "#1edac6", }, }, splitLine: { show: false, lineStyle: { color: "rgba(61,91,98,0.8)", }, }, }, ], dataZoom: [ { // show: true, show: false, height: 4, bottom: 18, start: 10, end: 80, handleSize: "100%", fillerColor: "#94FA41", borderColor: "transparent", backgroundColor: "rgba(148, 250, 65, 0.2)", handleStyle: { color: "#94FA41", }, moveHandleSize: 0, textStyle: { color: "#fff", }, }, { type: "inside", show: true, height: 15, start: 1, end: 35, }, ], series: [ { smooth: true, //变为曲线 默认false折线 name: props.data.yinziName[0], type: "line", data: props.data.YAxis, areaStyle: { //折线图颜色半透明 color: { type: "linear", x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: "rgba(16, 104, 211, 0.8)", // 0% 处的颜色 }, { offset: 1, color: "rgba(16, 104, 211, 0)", // 100% 处的颜色 }, ], global: false, // 缺省为 false }, }, }, { // smooth: true,//变为曲线 默认false折线 yAxisIndex: 1, name: props.data.yinziName[1], type: "bar", barWidth: 12, itemStyle: { borderRadius: [0, 0, 6, 6], color: function () { return new echarts.graphic.LinearGradient( 0, 1, 0, 0, [ { offset: 0, color: "#1fdbc7", }, { offset: 1, color: "rgba(30, 218, 196,0.6)", }, ], false ); }, }, // showBackground: true, backgroundStyle: { color: "transparent", borderWidth: 1, borderColor: "rgba(148, 250, 65, 0.2)", }, data: props.data.YAxis2, }, // { // smooth: true,//变为曲线 默认false折线 // name: '当前SS', // type: "line", // yAxisIndex: 1, // data: props.data.YAxis3, // }, ], }; option && chartDom.setOption(option, true); allData.chart = chartDom; }; watch( () => props.refresh, () => { if (allData.chartDom) { allData.chartDom.dispose(); allData.chartDom = null; } setTimeout(() => { init(); }, 0); } ); onMounted(() => { init(); window.addEventListener("resize", resizeTheChart); }); return { ...toRefs(allData), resizeTheChart, init, }; }, }; </script>