This commit is contained in:
2024-05-20 14:56:35 +08:00
29 changed files with 738 additions and 468 deletions

View File

@@ -8,33 +8,25 @@
<template>
<chart-container class="bar-chart-base">
<div class="legend">
<span
v-for="item in legend"
:key="item.label"
class="legend-item"
:style="{ fontSize: isFullscreen ? '0.58vw' : '0.54vw' }"
>{{ item.label }}</span
>
<span v-for="item in legend" :key="item.label" class="legend-item"
:style="{ fontSize: isFullscreen ? '0.58vw' : '0.54vw' }">{{ item.label }}</span>
</div>
<div
ref="chart"
style="max-width: 40vw"
:style="{ height: vHeight + 'vh' }"
></div>
<div ref="chart" :style="{ height: '95%',width: width}"></div>
</chart-container>
</template>
<script>
import screenfull from "screenfull";
import ChartContainer from "./ChartContainer.vue";
import chartMixin from "@/mixins/chart.js";
import { debounce } from "@/utils/debounce";
// import chartMixin from "@/mixins/chart.js";
import * as echarts from "echarts";
export default {
name: "BarChartBase",
components: {
ChartContainer,
},
mixins: [chartMixin],
// mixins: [chartMixin],
props: {
vHeight: {
type: Number,
@@ -59,6 +51,7 @@ export default {
},
data() {
return {
width: '',
isFullscreen: false,
actualOptions: null,
options: {
@@ -182,8 +175,26 @@ export default {
},
};
},
computed: {
isOpen() {
return this.$store.getters.sidebar.opened
},
},
watch: {
/** 全屏状态切换时,对柱子粗细和字体大小进行相应调整 */
isOpen(val) {
// console.log(val)
if (val === true) {
console.log('ztl')
this.width = 95 + '%'
this.canvasReset()
console.log(this.width)
} else {
this.watch = 100 + '%'
this.canvasReset()
}
},
isFullscreen(val) {
this.actualOptions.series.map((item) => {
item.barWidth = val ? 18 : 12;
@@ -191,11 +202,26 @@ export default {
this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initOptions(this.actualOptions);
this.initChart(this.actualOptions);
if (val === false && this.isOpen === true) {
console.log(val)
this.width = 97 + '%'
this.canvasReset()
} else if (val === false && this.isOpen === false) {
this.watch = 100 + '%'
this.canvasReset()
}
// this.actualOptions.series.map((item) => {
// item.barWidth = val ? 18 : 12;
// });
// this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initChart(this.actualOptions);
},
series(val) {
if (!val) {
this.initOptions(this.options);
this.initChart(this.options);
return;
}
const actualOptions = JSON.parse(JSON.stringify(this.options));
@@ -205,18 +231,41 @@ export default {
actualOptions.series[1].data = val?.[1]?.data || [];
actualOptions.series[1].name = val?.[1]?.name || "";
this.actualOptions = actualOptions;
this.initOptions(actualOptions);
this.initChart(actualOptions);
},
},
mounted() {
this.actualOptions = this.options;
this.initOptions(this.options);
if (screenfull.isEnabled) {
screenfull.on("change", () => {
this.isFullscreen = screenfull.isFullscreen;
});
}
this.actualOptions = this.options
this.canvasReset();
window.addEventListener("resize", this.canvasReset);
},
beforeDestroy() {
if (this.chart) {
this.chart.dispose();
}
},
destroyed() {
window.removeEventListener("resize", this.canvasReset);
},
methods: {
canvasReset() {
debounce(() => {
this.initChart();
}, 500)();
},
initChart() {
if (this.chart) {
this.chart.dispose();
}
this.chart = echarts.init(this.$refs.chart);
this.chart.setOption(this.actualOptions);
},
},
};
</script>

View File

@@ -62,7 +62,6 @@ export default {
methods: {
toggleFullScreen() {
this.isFullscreen = !this.isFullscreen;
screenfull.toggle(document.querySelector(".copilot-layout"))
// 矫正宽度
// const el = document.querySelector(".copilot-layout");

View File

@@ -11,7 +11,7 @@
<span v-for="item in legend" :key="item.label" class="legend-item"
:style="{ fontSize: isFullscreen ? '0.58vw' : '0.54vw' }">{{ item.label }}</span>
</div>
<div ref="elsChart" :style="{ height: '100%',width: width}"></div>
<div ref="elsChart" :style="{ height: '95%',width: width}"></div>
</chart-container>
</template>
@@ -36,12 +36,12 @@ export default {
type: Array,
required: true,
},
xAxis: {
type: Array,
required: true,
},
// xAxis: {
// type: Array,
// required: true,
// },
series: {
type: Array,
type: Object,
required: true,
},
in: {
@@ -84,19 +84,16 @@ export default {
// },
grid: {
left: '3%',
right: '4%',
right: '2%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
xAxis:{
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
}
],
yAxis: [
{
},
yAxis: {
min: function () { // 取最小值向下取整为最小刻度
return 0
},
@@ -143,7 +140,6 @@ export default {
// }
// },
},
],
series: [
{
name: '瑞昌',
@@ -367,22 +363,31 @@ export default {
watch: {
isOpen(val) {
if (val === true) {
this.width = '99%'
this.width = 97 + '%'
this.canvasReset()
console.log(this.width)
} else {
this.watch = 100 + '%'
this.canvasReset()
}
},
/** 全屏状态切换时,对柱子粗细和字体大小进行相应调整 */
isFullscreen(val) {
this.actualOptions.series.map((item) => {
item.barWidth = val ? 18 : 12;
});
this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
if (val === false && this.isOpen === true) {
this.width = 97 + '%'
this.canvasReset()
} else if (val === false && this.isOpen === false) {
this.watch = 100 + '%'
this.canvasReset()
}
// this.actualOptions.series.map((item) => {
// item.barWidth = val ? 18 : 12;
// });
// this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initChart(this.actualOptions);
},
series(val) {
@@ -391,21 +396,26 @@ export default {
return;
}
const actualOptions = JSON.parse(JSON.stringify(this.options));
actualOptions.series[0].data = val[0].data;
actualOptions.series[0].name = val[0].name;
actualOptions.series[1].data = val?.[1]?.data || [];
actualOptions.series[1].name = val?.[1]?.name || "";
actualOptions.xAxis.data = val.times
actualOptions.series[0].data = val[0]
actualOptions.series[1].data = val[1];
actualOptions.series[2].data = val[2];
actualOptions.series[3].data = val[3];
actualOptions.series[4].data = val[4];
actualOptions.series[5].data = val[5];
actualOptions.series[6].data = val[6];
this.actualOptions = actualOptions;
this.initChart(actualOptions);
},
},
mounted() {
// if (screenfull.isEnabled) {
// screenfull.on("change", () => {
// this.isFullscreen = screenfull.isFullscreen;
// });
// }
if (screenfull.isEnabled) {
screenfull.on("change", () => {
this.isFullscreen = screenfull.isFullscreen;
});
}
this.actualOptions = this.options
this.canvasReset();
window.addEventListener("resize", this.canvasReset);

View File

@@ -11,7 +11,7 @@
<span v-for="item in legend" :key="item.label" class="legend-item"
:style="{ fontSize: isFullscreen ? '0.58vw' : '0.54vw' }">{{ item.label }}</span>
</div>
<div ref="waterChart" :style="{ height: '100%',width: width}"></div>
<div ref="waterChart" :style="{ height: '95%',width: width}"></div>
</chart-container>
</template>
@@ -36,12 +36,12 @@ export default {
type: Array,
required: true,
},
xAxis: {
type: Array,
required: true,
},
// xAxis: {
// type: Array,
// required: true,
// },
series: {
type: Array,
type: Object,
required: true,
},
in: {
@@ -56,8 +56,8 @@ export default {
actualOptions: null,
options: {
grid: {
left: "1%",
right: "4%",
left: "3%",
right: "2%",
bottom: "3%",
top: "15%",
containLabel: true,
@@ -88,15 +88,12 @@ export default {
bottom: '3%',
containLabel: true
},
xAxis: [
{
xAxis:{
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
}
],
yAxis: [
{
// boundaryGap: false,
data: []
},
yAxis: {
min: function () { // 取最小值向下取整为最小刻度
return 0
},
@@ -143,7 +140,6 @@ export default {
// }
// },
},
],
series: [
{
name: '瑞昌',
@@ -173,7 +169,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '邯郸',
@@ -203,7 +199,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '株洲',
@@ -233,7 +229,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '佳木斯',
@@ -263,7 +259,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '成都',
@@ -293,7 +289,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '凯盛',
@@ -323,7 +319,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
{
name: '蚌埠',
@@ -353,7 +349,7 @@ export default {
// emphasis: {
// focus: 'series'
// },
data: [120, 132, 101, 134, 90, 230, 210]
data: []
},
]
},
@@ -364,8 +360,9 @@ export default {
// console.log(val)
if (val === true) {
console.log('ztl')
this.width = '99%'
this.width = 97 + '%'
this.canvasReset()
console.log(this.width)
} else {
this.watch = 100 + '%'
@@ -374,15 +371,20 @@ export default {
},
/** 全屏状态切换时,对柱子粗细和字体大小进行相应调整 */
isFullscreen(val) {
if (val === true && this.isOpen === true) {
this.width = '99%'
if (val === false && this.isOpen === true) {
console.log(val)
this.width = 97 + '%'
this.canvasReset()
} else if(val === false && this.isOpen === false) {
this.watch = 100 + '%'
this.canvasReset()
}
this.actualOptions.series.map((item) => {
item.barWidth = val ? 18 : 12;
});
this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
// this.actualOptions.series.map((item) => {
// item.barWidth = val ? 18 : 12;
// });
// this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initChart(this.actualOptions);
},
series(val) {
@@ -390,11 +392,22 @@ export default {
this.initChart(this.options);
return;
}
const actualOptions = JSON.parse(JSON.stringify(this.options));
actualOptions.series[0].data = val[0].data;
actualOptions.series[0].name = val[0].name;
actualOptions.series[1].data = val?.[1]?.data || [];
actualOptions.series[1].name = val?.[1]?.name || "";
const actualOptions = JSON.parse(JSON.stringify(this.options))
// console.log(actualOptions)
actualOptions.xAxis.data = val.times
// actualOptions.series.forEach((ele,index) => {
// ele.data = val.index
// })
actualOptions.series[0].data = val[0]
actualOptions.series[1].data = val[1];
actualOptions.series[2].data = val[2];
actualOptions.series[3].data = val[3];
actualOptions.series[4].data = val[4];
actualOptions.series[5].data = val[5];
actualOptions.series[6].data = val[6];
// actualOptions.series[1].data = val?.[1]?.data || [];
// actualOptions.series[1].name = val?.[1]?.name || "";
this.actualOptions = actualOptions;
this.initChart(actualOptions);
},

View File

@@ -1,7 +1,7 @@
<!--
* @Author: zhp
* @Date: 2024-05-13 14:08:51
* @LastEditTime: 2024-05-14 08:46:07
* @LastEditTime: 2024-05-17 09:37:01
* @LastEditors: zhp
* @Description:
-->
@@ -12,7 +12,7 @@
<!-- <span v-for="item in legend" :key="item.label" class="legend-item"
:style="{ fontSize: isFullscreen ? '0.58vw' : '0.54vw' }">{{ item.label }}</span> -->
</div>
<div ref="gasChart" :style="{ height: '100%',width: width}"></div>
<div ref="gasChart" :style="{ height: '95%',width: width}"></div>
</chart-container>
</template>
@@ -33,22 +33,22 @@ export default {
type: Number,
default: 38,
},
legend: {
type: Array,
required: false,
},
// legend: {
// type: Array,
// required: false,
// },
xAxis: {
type: Array,
required: true,
},
series: {
type: Array,
required: true,
},
in: {
type: String,
default: "",
required: false,
},
// in: {
// type: String,
// default: "",
// },
},
data() {
return {
@@ -57,8 +57,8 @@ export default {
actualOptions: null,
options: {
grid: {
left: "1%",
right: "4%",
left: "3%",
right: "2%",
bottom: "3%",
top: "15%",
containLabel: true,
@@ -140,38 +140,38 @@ export default {
},
data: [], // this.series[0].data,
},
{
name: "", // this.series[1].name,
type: "bar",
barWidth: 12,
// tooltip: {
// valueFormatter: function (value) {
// return value + " ml";
// },
// },
itemStyle: {
borderRadius: [10, 10, 0, 0],
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "#57abf8", // 0% 处的颜色
},
{
offset: 1,
color: "#364BFE66", // 100% 处的颜色
},
],
global: false, // 缺省为 false
},
},
data: [], // this.series[1].data,
},
// {
// name: "", // this.series[1].name,
// type: "bar",
// barWidth: 12,
// // tooltip: {
// // valueFormatter: function (value) {
// // return value + " ml";
// // },
// // },
// itemStyle: {
// borderRadius: [10, 10, 0, 0],
// color: {
// type: "linear",
// x: 0,
// y: 0,
// x2: 0,
// y2: 1,
// colorStops: [
// {
// offset: 0,
// color: "#57abf8", // 0% 处的颜色
// },
// {
// offset: 1,
// color: "#364BFE66", // 100% 处的颜色
// },
// ],
// global: false, // 缺省为 false
// },
// },
// data: [], // this.series[1].data,
// },
],
},
};
@@ -185,39 +185,44 @@ export default {
isOpen(val) {
// console.log(val)
if (val === true) {
console.log('ryf')
this.width = '99%'
this.width = 97 + '%'
this.canvasReset()
console.log(this.width)
} else {
console.log('ryf')
this.watch = 100 + '%'
this.canvasReset()
}
},
/** 全屏状态切换时,对柱子粗细和字体大小进行相应调整 */
isFullscreen(val) {
if (val === true && this.isOpen === true) {
this.width = '99%'
if (val === false && this.isOpen === true) {
this.width = 97 + '%'
this.canvasReset()
} else if (val === false && this.isOpen === false) {
this.watch = 100 + '%'
this.canvasReset()
}
this.actualOptions.series.map((item) => {
item.barWidth = val ? 18 : 12;
});
this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initOptions(this.actualOptions);
// this.actualOptions.series.map((item) => {
// item.barWidth = val ? 18 : 12;
// });
// this.actualOptions.xAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.axisLabel.fontSize = val ? 18 : 12;
// this.actualOptions.yAxis.nameTextStyle.fontSize = val ? 18 : 12;
this.initChart(this.actualOptions);
},
series(val) {
if (!val) {
this.initOptions(this.options);
this.initChart(this.options);
return;
}
const actualOptions = JSON.parse(JSON.stringify(this.options));
console.log('actualOptions', this.options)
actualOptions.series[0].data = val[0].data;
actualOptions.series[0].name = val[0].name;
actualOptions.series[1].data = val?.[1]?.data || [];
actualOptions.series[1].name = val?.[1]?.name || "";
actualOptions.series[0].data = val;
// actualOptions.series[0].name = val[0].name;
// actualOptions.series[1].data = val?.[1]?.data || [];
// actualOptions.series[1].name = val?.[1]?.name || "";
this.actualOptions = actualOptions;
this.initChart(actualOptions);
},

View File

@@ -1,8 +1,8 @@
<!--
<!--
filename: select.vue
author: liubin
date: 2024-04-17 09:50:03
description:
description:
-->
<template>