Files
emsfront/src/views/ems/dzjk/sbjk/ssyx/DcpjwdChart.vue

126 lines
3.2 KiB
Vue
Raw Normal View History

2025-06-18 01:01:17 +08:00
<template>
2025-09-27 14:50:20 +08:00
<el-card
shadow="always"
class="common-card-container common-card-container-body-no-padding"
>
2025-06-18 01:01:17 +08:00
<div slot="header">
<span class="card-title">电池平均温度</span>
</div>
2025-09-27 14:50:20 +08:00
<div style="height: 360px" id="dcpjwdChart" />
2025-06-18 01:01:17 +08:00
</el-card>
</template>
<style scoped lang="scss"></style>
<script>
2025-09-27 14:50:20 +08:00
import * as echarts from "echarts";
import resize from "@/mixins/ems/resize";
import { batteryAveTemp } from "@/api/ems/dzjk";
2025-06-18 01:01:17 +08:00
export default {
mixins: [resize],
data() {
return {
2025-09-27 14:50:20 +08:00
chart: null,
};
2025-06-18 01:01:17 +08:00
},
mounted() {
2025-09-27 14:50:20 +08:00
this.chart = echarts.init(document.querySelector("#dcpjwdChart"));
2025-06-18 01:01:17 +08:00
},
beforeDestroy() {
if (!this.chart) {
2025-09-27 14:50:20 +08:00
return;
2025-06-18 01:01:17 +08:00
}
2025-09-27 14:50:20 +08:00
this.chart.dispose();
this.chart = null;
2025-06-18 01:01:17 +08:00
},
methods: {
2025-11-25 17:56:12 +08:00
init(siteId,timeRange) {
2025-09-27 14:50:20 +08:00
this.chart.showLoading();
2025-11-25 17:56:12 +08:00
const [startTime='', endTime=''] = timeRange;
batteryAveTemp(siteId,startTime,endTime)
2025-09-27 14:50:20 +08:00
.then((response) => {
this.setOption(response?.data?.batteryAveTempList || []);
})
2025-09-27 14:50:20 +08:00
.finally(() => {
this.chart.hideLoading();
});
2025-06-18 01:01:17 +08:00
},
2025-09-27 14:50:20 +08:00
setOption(data) {
let xdata = [],
ydata = [];
data.forEach((element) => {
xdata.push(element.createDate);
2025-11-26 17:50:06 +08:00
ydata.push(
{
value: element.batteryTemp,
year: element.dateDay
}
);
2025-09-27 14:50:20 +08:00
});
this.chart && this.chart.setOption({
2025-09-27 14:50:20 +08:00
legend: {
left: "center",
top: "5",
itemWidth: 10,
itemHeight: 5,
textStyle: {
fontSize: 9,
},
2025-06-18 01:01:17 +08:00
},
grid: {
2025-09-27 14:50:20 +08:00
containLabel: true,
},
tooltip: {
2025-11-26 17:50:06 +08:00
show:true,
2025-09-27 14:50:20 +08:00
trigger: "axis",
axisPointer: {
// 坐标轴指示器,坐标轴触发有效
type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
},
2025-11-26 17:50:06 +08:00
formatter :(params)=>{
if(params.length <= 0) return
2025-11-27 15:58:23 +08:00
let result = (params[0].data.year || '')+' '+params[0].name + '<div>'
2025-11-26 17:50:06 +08:00
params.forEach(item=>{
const {color,seriesName,value} = item
result += `<div style="position: relative;padding-left:20px;line-height: 20px;">
<div style="position: absolute;top:50%;left:0;width:12px;height:12px;border-radius:100%;background: ${color};transform: translateY(-50%)"></div>
<span>${seriesName}</span><span style="margin-left:20px;font-weight: 700">${value}</span></div>`
})
result+='</div>'
return result
}
},
2025-09-27 14:50:20 +08:00
textStyle: {
color: "#333333",
2025-06-18 01:01:17 +08:00
},
2025-09-27 14:50:20 +08:00
xAxis: { type: "category", data: xdata },
2025-06-18 01:01:17 +08:00
yAxis: {
2025-09-27 14:50:20 +08:00
type: "value",
2025-06-18 01:01:17 +08:00
},
dataZoom: [
{
2025-09-27 14:50:20 +08:00
type: "inside",
start: 0,
2025-09-27 14:50:20 +08:00
end: 100,
},
{
start: 0,
2025-09-27 14:50:20 +08:00
end: 100,
},
],
2025-06-18 01:01:17 +08:00
series: [
{
2025-09-27 14:50:20 +08:00
type: "line",
name: `电池平均温度`,
areaStyle: {
2025-09-27 14:50:20 +08:00
// color:'#FFBD00'
},
2025-09-27 14:50:20 +08:00
data: ydata,
},
],
},true);
2025-09-27 14:50:20 +08:00
},
},
};
2025-06-18 01:01:17 +08:00
</script>