vue3中使用Echarts绘制带表格背景的折线图
时间: 2024-03-26 20:40:42 浏览: 11
指示灯闪烁
{
LED = 0;
delay_ms(500);
LED = 1;
delay_ms(500);
}
else
{
LED = 1;
}
if(voltage > THRESHOLD) //首先,需要安装 Echarts 和 Vue3:
```
npm install echarts vue@next
```
然后,在 Vue 组件中引用 Echarts:
```vue
<template>
<div class="chart-container">
<div ref="chart" class=" 如果光照强度高于自己设定的阈值,蜂鸣器发出报警声
{
BEEPchart"></div>
</div>
</template>
<script>
import { onMounted, ref } from 'vue';
import * as echarts = 0;
}
else
{
BEEP = 1;
}
if(!S11) // 如果 from 'echarts';
export default {
name: 'LineChart',
setup() {
const chart = ref(null);
onMounted按下了S11键,发送当前温度值到电脑的串口助手上
{
uart_send('T(() => {
const myChart = echarts.init(chart.value);
// 设置图表配置项
const option = {
//');
uart_send(':');
uart_send((int)temperature / 10 + '0');
uart_send((int)temperature % 10 + '0');
uart_send('.');
uart_send((int)(temperature * 10) % 10 + '0');
设置表格背景
grid: {
top: 50,
left: 50,
right: 50,
uart_send('\n');
delay_ms(100);
}
if(!S15) // 如果按下: 50,
containLabel: true,
backgroundColor: '#fff',
},
// 设置折线图数据
xAxisS15键,: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
发送当前光敏电阻对应的电压值到电脑的串口助手上
{
uart_send('V yAxis: {},
series: [
{
type: 'line',
data: [820, 932, 901, 934');
uart_send(':');
uart_send((int)voltage / 1000 + '0');
uart_send(((int)voltage, 1290, 1330, 1320],
showSymbol: false,
},
],
};
// 使用刚 / 100) % 10 + '0');
uart_send(((int)voltage / 10) % 10 + '0');
指定的配置项和数据显示图表。
myChart.setOption(option);
});
return {
chart,
};
uart_send((int)voltage % 10 + '0');
uart_send('.');
uart_send((int)(voltage * 10) % 10 + '0');
uart_send('\n');
delay_ms(100);
}
}
}
/* 串口 },
};
</script>
<style scoped>
.chart-container {
height: 500px;
}
.chart {
height: 100%;
}
</中断处理函数 */
void uart_isr() interrupt 4
{
if(RI) // 如果接收到了数据
style>
```
在上面的代码中,我们设置了一个 `grid` 对象来定义表格背景,然后 {
RI = 0;
}
if(TI) // 如果发送数据完成
{
TI = 0;
设置了一个 `xAxis` 和一个 `series` 对象来定义折线图的数据。最后,在 `onMounted` }
}
```
在上述代码中,我们首先定义了各个IO口和常量,然后通过`adc 钩子函数中,我们初始化了 Echarts 实例,并使用 `setOption` 方法将配置项和数据显示在图表中。
这样,我们就可以在 Vue3 中使用 Echarts 绘制带表格背景的折线图了。