Skip to content

Commit 75b9937

Browse files
committed
初步完成波形发生器与示波器图表组件
1 parent 33ce447 commit 75b9937

File tree

6 files changed

+402
-19
lines changed

6 files changed

+402
-19
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>ESP32WebScope</title>
77
</head>
8-
<body>
8+
<body style="margin: 0;">
99
<div id="app"></div>
1010
<script type="module" src="/src/main.ts"></script>
1111
</body>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12+
"echarts": "^5.3.3",
1213
"element-plus": "^2.2.9",
1314
"vue": "^3.2.37"
1415
},

src/App.vue

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
<template>
22
<div class="container" style="justify-content:normal;">
3-
<el-row justify="end" style="height:32px;">
4-
<el-form-item label="暗黑模式">
5-
<el-switch v-model="switchVal" @change="toggleDark()" inline-prompt active-text="" inactive-text="" />
6-
</el-form-item>
7-
</el-row>
3+
84
<el-row>
95
<!-- 左半屏幕 -->
106
<el-col :span="12">
117
<div class="LeftMain">
128
<WaveGen msg="波形发生器控制面板" />
9+
<WaveGenChart width="550" height="350" container="WaveGenChart"></WaveGenChart>
1310
</div>
1411
</el-col>
1512
<!-- 右半屏幕 -->
1613
<el-col :span="12">
14+
<el-row justify="end" style="height:32px;">
15+
<el-form-item label="深色模式">
16+
<el-switch v-model="switchVal" @change="toggleDark()" inline-prompt active-text="" inactive-text="" />
17+
</el-form-item>
18+
</el-row>
19+
<el-row>
20+
<el-col :span="24">
21+
<h2>ESP32示波器面板</h2>
22+
<OSChart width="550" height="350" container="OSChart"></OSChart>
23+
</el-col>
24+
</el-row>
25+
1726
</el-col>
1827
</el-row>
1928

2029
</div>
2130
</template>
2231
<style>
23-
2432
.LeftMain {
2533
width: 100%;
26-
height: 100%;
34+
height: auto;
2735
}
2836
2937
.el-row {
@@ -45,25 +53,23 @@ import { useDark, useToggle } from '@vueuse/core'
4553
const isDark = useDark()
4654
const toggleDark = useToggle(isDark)
4755
48-
const switchVal = ref(true)
56+
const switchVal = ref(false)
4957
5058
51-
function onClick() {
52-
ElNotification({
53-
type: 'success',
54-
title: '已成功发送邮件',
55-
message: '验证码区分大小写,有效期5分钟',
56-
duration: 3000,
57-
})
58-
}
5959
</script>
6060
<script lang="ts">
6161
import WaveGen from './components/WaveGen.vue'
62+
import WaveGenChart from './components/WaveGenChart.vue'
63+
import OSChart from './components/OSChart.vue'
6264
export default {
6365
name: 'App',
6466
components: {
6567
//2.声明或注册组件
66-
WaveGen
68+
WaveGen,
69+
WaveGenChart,
70+
OSChart
6771
}
6872
}
73+
74+
6975
</script>

src/components/OSChart.vue

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<template>
2+
<div :style="`width:${width}px;height:${height}px;`" :id="container" class="OSChart"></div>
3+
4+
</template>
5+
6+
<script lang="ts" setup>
7+
import * as echarts from 'echarts/core';
8+
import {
9+
ToolboxComponent,
10+
ToolboxComponentOption,
11+
TooltipComponent,
12+
TooltipComponentOption,
13+
GridComponent,
14+
GridComponentOption,
15+
DataZoomComponent,
16+
DataZoomComponentOption
17+
} from 'echarts/components';
18+
import { LineChart, LineSeriesOption } from 'echarts/charts';
19+
import { UniversalTransition } from 'echarts/features';
20+
import { CanvasRenderer } from 'echarts/renderers';
21+
import { onMounted } from 'vue';
22+
23+
echarts.use([
24+
ToolboxComponent,
25+
TooltipComponent,
26+
GridComponent,
27+
DataZoomComponent,
28+
LineChart,
29+
CanvasRenderer,
30+
UniversalTransition
31+
]);
32+
33+
type EChartsOption = echarts.ComposeOption<
34+
| ToolboxComponentOption
35+
| TooltipComponentOption
36+
| GridComponentOption
37+
| DataZoomComponentOption
38+
| LineSeriesOption
39+
>;
40+
// 2.定义传入的参数
41+
const props = defineProps({
42+
width: {
43+
type: String,
44+
default: "550",
45+
},
46+
height: {
47+
type: String,
48+
default: "350",
49+
},
50+
//首次加载
51+
isFirst: {
52+
type: Boolean,
53+
default: false,
54+
},
55+
//组件唯一值
56+
container: {
57+
type: String,
58+
default: "WaveGenChart",
59+
},
60+
});
61+
62+
var option: EChartsOption;
63+
64+
function func(x: number) {
65+
x /= 10;
66+
return Math.sin(x) * 3.3;
67+
}
68+
69+
function generateData() {
70+
let data = [];
71+
for (let i = 0; i <= 300; i += 1) {
72+
data.push([i, func(i)]);
73+
}
74+
return data;
75+
}
76+
77+
option = {
78+
animation: false,
79+
grid: {
80+
top: 40,
81+
left: 50,
82+
right: 40,
83+
bottom: 50
84+
},
85+
tooltip: {
86+
show: true,
87+
trigger: 'axis',
88+
axisPointer: {
89+
type: 'cross'
90+
}
91+
},
92+
toolbox: {
93+
show: true,
94+
feature: {
95+
dataZoom: {
96+
yAxisIndex: 'none'
97+
},
98+
dataView: {
99+
readOnly: false
100+
},
101+
magicType: {
102+
type: ['line', 'line']
103+
},
104+
restore: {},
105+
saveAsImage: {}
106+
}
107+
},
108+
xAxis: {
109+
name: 'x',
110+
min: 0,
111+
max: 256,
112+
minorTick: {
113+
show: true
114+
},
115+
minorSplitLine: {
116+
show: true
117+
}
118+
},
119+
yAxis: {
120+
name: 'y',
121+
min: -5,
122+
max: 5,
123+
minorTick: {
124+
show: true
125+
},
126+
minorSplitLine: {
127+
show: true
128+
}
129+
},
130+
dataZoom: [
131+
{
132+
show: true,
133+
type: 'inside',
134+
filterMode: 'filter',
135+
xAxisIndex: [0],
136+
startValue: -20,
137+
endValue: 20
138+
},
139+
{
140+
show: true,
141+
type: 'inside',
142+
filterMode: 'empty',
143+
yAxisIndex: [0],
144+
startValue: -20,
145+
endValue: 20
146+
}
147+
],
148+
series: [
149+
{
150+
type: 'line',
151+
showSymbol: false,
152+
clip: true,
153+
data: generateData()
154+
}
155+
]
156+
};
157+
158+
onMounted(() => {
159+
var chartDom = document.getElementById(props.container) as HTMLElement
160+
var myChart = echarts.init(chartDom);
161+
option && myChart.setOption(option);
162+
})
163+
164+
</script>
165+
166+
<script lang="ts">
167+
export default {
168+
name: "OSChart",
169+
props2: {
170+
msg: String,
171+
option: Object
172+
},
173+
darkMode(isDark: boolean) {
174+
let chartDom1 = document.getElementById(this.container) as HTMLElement
175+
if (isDark)
176+
var chart = echarts.init(chartDom1, 'dark');
177+
else
178+
var chart = echarts.init(chartDom1);
179+
}
180+
}
181+
182+
</script>
183+
184+
<style>
185+
.OSChart {
186+
margin: 0 auto;
187+
}
188+
</style>

src/components/WaveGen.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default {
103103
<style>
104104
.waveGen {
105105
width: 50%;
106-
height: 100%;
106+
height: auto;
107107
margin: 0 auto;
108108
font-size: 2em;
109109
}

0 commit comments

Comments
 (0)