Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 501fa20

Browse files
committed
图表曲线深色模式
1 parent a0c8516 commit 501fa20

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

frontend/src/components/ChartCard.vue

+58-12
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,38 @@
55
</template>
66
<script>
77
import timechart from "timechart";
8+
import colors from "vuetify/lib/util/colors";
89
export default {
910
data: () => ({
1011
ws: null,
1112
chart: null,
12-
iColor: 0,
13-
colors: [
14-
"#F44336",
15-
"#9C27B0",
16-
"#3F51B5",
17-
"#00BCD4",
18-
"#4CAF50",
19-
"#FF9800",
20-
"#795548"
21-
]
13+
indexColor: 0,
14+
lineColors: {
15+
light: [
16+
colors.red.lighten1,
17+
colors.green.lighten1,
18+
colors.orange.lighten1,
19+
colors.purple.lighten1,
20+
colors.indigo.lighten1,
21+
colors.teal.lighten1,
22+
colors.pink.lighten1
23+
],
24+
dark: [
25+
colors.red.darken4,
26+
colors.green.darken4,
27+
colors.orange.darken4,
28+
colors.purple.darken4,
29+
colors.indigo.darken4,
30+
colors.teal.darken4,
31+
colors.pink.darken4
32+
]
33+
}
2234
}),
35+
computed: {
36+
isDark() {
37+
return this.$vuetify.theme.dark;
38+
}
39+
},
2340
created() {
2441
this.initWS();
2542
},
@@ -35,9 +52,28 @@ export default {
3552
realTime: true
3653
});
3754
},
55+
watch: {
56+
isDark: function() {
57+
if (this.isDark) {
58+
for (var i in this.chart.options.series) {
59+
this.chart.options.series[i].color = this.lineColors.dark[i];
60+
}
61+
} else {
62+
for (i in this.chart.options.series) {
63+
this.chart.options.series[i].color = this.lineColors.light[i];
64+
}
65+
}
66+
this.chart.update();
67+
}
68+
},
3869
methods: {
3970
initWS() {
40-
this.ws = new WebSocket((document.location.protocol=='https:'?'wss':'ws')+"://" + window.location.host + "/ws");
71+
this.ws = new WebSocket(
72+
(document.location.protocol == "https:" ? "wss" : "ws") +
73+
"://" +
74+
window.location.host +
75+
"/ws"
76+
);
4177
this.ws.onopen = this.WSonopen;
4278
this.ws.onclose = this.WSclose;
4379
this.ws.onmessage = this.WSonmessage;
@@ -55,6 +91,15 @@ export default {
5591
WSonerror(evt) {
5692
console.log("ERROR: " + evt.data);
5793
},
94+
selectColor() {
95+
this.indexColor++;
96+
this.indexColor == this.lineColors.light.length ? 0 : this.indexColor;
97+
if (this.$vuetify.theme.dark) {
98+
return this.lineColors.dark[this.indexColor];
99+
} else {
100+
return this.lineColors.light[this.indexColor];
101+
}
102+
},
58103
praseWS(data) {
59104
if (data != "") {
60105
const jsonWS = JSON.parse(data);
@@ -68,9 +113,10 @@ export default {
68113
y: jsonWS.DataPack[i].Data
69114
});
70115
} else {
116+
const color = this.selectColor();
71117
this.chart.options.series.push({
72118
name: jsonWS.DataPack[i].Name,
73-
color: this.colors[this.iColor],
119+
color: color,
74120
data: [{ x: jsonWS.DataPack[i].Tick, y: jsonWS.DataPack[i].Data }]
75121
});
76122
this.iColor++;

0 commit comments

Comments
 (0)