|
@@ -0,0 +1,372 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <div class="select-veido">
|
|
|
+ <el-select
|
|
|
+ style="margin-top:10px"
|
|
|
+ v-model="currentChartId"
|
|
|
+ placeholder="请选择"
|
|
|
+ @change="selectChart()"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in chartoptions"
|
|
|
+ :key="item.id+''"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.id"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ ref="testLine"
|
|
|
+ style="width: 450px; height: 400px; margin:0px auto"
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { mapState } from "vuex";
|
|
|
+
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ chartoptions: [
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ label: "流量",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ label: "浓度",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ type: {
|
|
|
+ name1: "chouqiliuliang_after",
|
|
|
+ name2: "paiqiliuliang_after",
|
|
|
+ },
|
|
|
+ gasId: "35",
|
|
|
+ title: "流量",
|
|
|
+ gasUnit: "%",
|
|
|
+ currentChartId: "流量",
|
|
|
+ currentChartTitle: "流量",
|
|
|
+ paiqidata: new Array(30).fill("-"),
|
|
|
+ chouqidata: new Array(30).fill("-"),
|
|
|
+ xData: new Array(30).fill("-"),
|
|
|
+ count: 0,
|
|
|
+ myChart: null,
|
|
|
+ option: {
|
|
|
+ color: ["#41D6C3", "#FA8072"],
|
|
|
+ tooltip: {
|
|
|
+ trigger: "axis",
|
|
|
+ axisPointer: {
|
|
|
+ type: "cross",
|
|
|
+ label: {
|
|
|
+ backgroundColor: "#6a7985",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ backgroundColor: "#fff",
|
|
|
+ padding: 10,
|
|
|
+ textStyle: {
|
|
|
+ fontSize: 12,
|
|
|
+ color: "#152934",
|
|
|
+ lineHeight: 24,
|
|
|
+ },
|
|
|
+ extraCssText:
|
|
|
+ "box-shadow: 0 0 3px rgba(0, 0, 0, 0.3); border-radius: 0;",
|
|
|
+ formatter: (params) => {
|
|
|
+ console.log("params", params);
|
|
|
+ var result = `${this.title}:${params[0].data}${this.gasUnit} <br/>`;
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ legend: {
|
|
|
+ orient: "vertical",
|
|
|
+ x: "left",
|
|
|
+ y: "top",
|
|
|
+ data: ["抽气流量", "排气流量"],
|
|
|
+ textStyle: {
|
|
|
+ fontWeight: "normal",
|
|
|
+ color: "#fff",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ yAxis: [
|
|
|
+ {
|
|
|
+ boundaryGap: [0, "100%"],
|
|
|
+ name: this.unit,
|
|
|
+ splitLine: {
|
|
|
+ show: true,
|
|
|
+ lineStyle: {
|
|
|
+ type: "dotted",
|
|
|
+ color: "rgba(155, 155, 155, 0.5)",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ axisLine: {
|
|
|
+ show: false,
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: "#fff",
|
|
|
+ fontSize: 11,
|
|
|
+ },
|
|
|
+ axisTick: { show: false },
|
|
|
+ type: "value",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ xAxis: [
|
|
|
+ {
|
|
|
+ // type: "time", // x轴为 时间轴
|
|
|
+ interval: 0,
|
|
|
+ splitLine: { show: false },
|
|
|
+ axisLine: {
|
|
|
+ lineStyle: { width: 0 },
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: "#fff",
|
|
|
+ fontSize: 11,
|
|
|
+ rotate: 30,
|
|
|
+ },
|
|
|
+ axisTick: { show: false },
|
|
|
+ boundaryGap: false,
|
|
|
+ data: [],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ title: {
|
|
|
+ text: "管道流量/浓度",
|
|
|
+ padding: [5, 230],
|
|
|
+ textStyle: {
|
|
|
+ fontWeight: "normal", //标题颜色
|
|
|
+ color: "#4ADEFE",
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: "抽气流量",
|
|
|
+ type: "line",
|
|
|
+ symbol: "none",
|
|
|
+ markPoint: {
|
|
|
+ label: {
|
|
|
+ normal: {
|
|
|
+ show: true,
|
|
|
+ backgroundColor: "#fff",
|
|
|
+ position: "top",
|
|
|
+ color: "#5AAAFA",
|
|
|
+ borderColor: "rgba(90,170,250,0.3)",
|
|
|
+ borderWidth: 1,
|
|
|
+ padding: 8,
|
|
|
+ formatter: "{b}: {c} ",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ symbol: "circle",
|
|
|
+ itemStyle: {
|
|
|
+ normal: {
|
|
|
+ borderColor: "rgba(90,170,250,0.3)",
|
|
|
+ borderWidth: 15,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ symbolSize: 7,
|
|
|
+ data: [{ type: "max", name: "Max" }],
|
|
|
+ },
|
|
|
+ lineStyle: { normal: { color: "#41D6C3", width: 1 } },
|
|
|
+ // lineStyle: {
|
|
|
+ // width: 2,
|
|
|
+ // color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
|
|
|
+ // {
|
|
|
+ // offset: 0,
|
|
|
+ // color: "#9effff",
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // offset: 1,
|
|
|
+ // color: "#9E87FF",
|
|
|
+ // },
|
|
|
+ // ]),
|
|
|
+ // },
|
|
|
+ areaStyle: { normal: { color: "#41D6C3", opacity: 0.5 } },
|
|
|
+ connectNulls: true,
|
|
|
+ data: [],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "排气流量",
|
|
|
+ type: "line",
|
|
|
+ symbol: "none",
|
|
|
+ markPoint: {
|
|
|
+ label: {
|
|
|
+ normal: {
|
|
|
+ show: true,
|
|
|
+ backgroundColor: "#fff",
|
|
|
+ position: "top",
|
|
|
+ color: "#5AAAFA",
|
|
|
+ borderColor: "rgba(90,170,250,0.3)",
|
|
|
+ borderWidth: 1,
|
|
|
+ padding: 8,
|
|
|
+ formatter: `{b}: {c} `,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ symbol: "circle",
|
|
|
+ itemStyle: {
|
|
|
+ normal: {
|
|
|
+ borderColor: "rgba(90,170,250,0.3)",
|
|
|
+ borderWidth: 15,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ symbolSize: 7,
|
|
|
+ data: [{ type: "max", name: "Max" }],
|
|
|
+ },
|
|
|
+ lineStyle: { normal: { color: "#CD5C5C", width: 1 } },
|
|
|
+ // lineStyle: {
|
|
|
+ // width: 2,
|
|
|
+ // color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
|
|
|
+ // {
|
|
|
+ // offset: 0,
|
|
|
+ // color: "#9effff",
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // offset: 1,
|
|
|
+ // color: "#9E87FF",
|
|
|
+ // },
|
|
|
+ // ]),
|
|
|
+ // },
|
|
|
+ areaStyle: { normal: { color: "#CD5C5C", opacity: 0.5 } },
|
|
|
+ connectNulls: true,
|
|
|
+ data: [],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(["websocketIP"]),
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ selectChart() {
|
|
|
+ for (let i in this.chartoptions) {
|
|
|
+ if (this.chartoptions[i].id == this.currentChartId) {
|
|
|
+ this.currentChartTitle = this.chartoptions[i].label;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 画流量对应的图
|
|
|
+ if (this.currentChartId == 1) {
|
|
|
+ this.title = this.currentChartTitle;
|
|
|
+ this.gasUnit = "%";
|
|
|
+ this.type = {
|
|
|
+ name1: "chouqiliuliang_after",
|
|
|
+ name2: "paiqiliuliang_after",
|
|
|
+ };
|
|
|
+ this.paiqidata = new Array(30).fill("-");
|
|
|
+ this.chouqidata = new Array(30).fill("-");
|
|
|
+ this.xData = new Array(30).fill("-");
|
|
|
+ this.count = 0;
|
|
|
+ } else {
|
|
|
+ // 画浓度对应的图
|
|
|
+ this.title = this.currentChartTitle;
|
|
|
+ this.gasUnit = "m^3/h";
|
|
|
+
|
|
|
+ this.type = {
|
|
|
+ name1: "chouqinongdu_after",
|
|
|
+ name2: "paiqinongdu_after",
|
|
|
+ };
|
|
|
+ this.paiqidata = new Array(30).fill("-");
|
|
|
+ this.chouqidata = new Array(30).fill("-");
|
|
|
+ this.xData = new Array(30).fill("-");
|
|
|
+ this.count = 0;
|
|
|
+ }
|
|
|
+ console.log("gasId", this.type["name1"]);
|
|
|
+ },
|
|
|
+ addData(data) {
|
|
|
+ // 先扩展数组,然后删除多余元素
|
|
|
+ console.log("data", data);
|
|
|
+ if (this.count < 30) {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ this.paiqidata[this.count] = data[i][this.type["name1"]];
|
|
|
+ this.chouqidata[this.count] = data[i][this.type["name2"]];
|
|
|
+ this.xData[this.count] = data[i]["date"].split(" ")[1];
|
|
|
+ }
|
|
|
+ this.count++;
|
|
|
+ } else {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ // 删除数组中的第一个项目
|
|
|
+ this.paiqidata.shift();
|
|
|
+ this.paiqidata.push(data[i][this.type["name1"]]);
|
|
|
+ this.chouqidata.shift();
|
|
|
+ this.chouqidata.push(data[i][this.type["name2"]]);
|
|
|
+ this.xData.shift();
|
|
|
+ this.xData.push(data[i]["date"].split(" ")[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.myChart.setOption({
|
|
|
+ xAxis: [
|
|
|
+ {
|
|
|
+ data: this.xData,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: "抽气流量",
|
|
|
+ data: this.chouqidata,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "排气流量",
|
|
|
+ data: this.paiqidata,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ // console.log("this.paiqidata", this.paiqidata);
|
|
|
+ // console.log("this.chouqidata", this.chouqidata);
|
|
|
+ // console.log("this.xData", this.xData);
|
|
|
+ },
|
|
|
+ initWebSocket() {
|
|
|
+ // 连接错误
|
|
|
+ this.websocket.onerror = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接发生错误 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
+ };
|
|
|
+ // 连接成功
|
|
|
+ this.websocket.onopen = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接成功 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
+ };
|
|
|
+ // 收到消息的回调
|
|
|
+ this.websocket.onmessage = (event) => {
|
|
|
+ // console.log("onmessage", event);
|
|
|
+ if (JSON.parse(event.data).length) {
|
|
|
+ this.addData(JSON.parse(event.data));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 连接关闭的回调
|
|
|
+ this.websocket.onclose = () => {
|
|
|
+ console.log(
|
|
|
+ "WebSocket连接关闭 状态码:" + this.websocket.readyState
|
|
|
+ );
|
|
|
+ };
|
|
|
+ // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
|
|
|
+ this.$once("hook:beforeDestroy", () => {
|
|
|
+ this.websocket.close();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ // 先画图
|
|
|
+ this.myChart = this.$echarts.init(this.$refs.testLine);
|
|
|
+ this.myChart.setOption(this.option);
|
|
|
+ this.websocket = new WebSocket(`ws://${this.websocketIP}/hbase/ws/belt/35`);
|
|
|
+ this.initWebSocket();
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped>
|
|
|
+.select-veido .el-select{
|
|
|
+ width: 100px;
|
|
|
+ margin-left: 10px;
|
|
|
+}
|
|
|
+.select-veido>>>.el-input--small .el-input__inner {
|
|
|
+
|
|
|
+ background: none;
|
|
|
+
|
|
|
+ }
|
|
|
+ .select-veido>>>.el-input__inner {
|
|
|
+
|
|
|
+ border: 0;
|
|
|
+
|
|
|
+ }
|
|
|
+</style>
|