生产监控前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.3 KiB

2 years ago
<!-- 线 + 柱混合图 -->
<template>
<el-card>
<template #header> 折线图 </template>
<div :id="id" :class="className" :style="{ height, width }" />
</el-card>
</template>
<script lang="ts" setup>
import * as echarts from 'echarts';
const props = defineProps({
id: {
type: String,
default: 'lineChart'
},
className: {
type: String,
default: ''
},
width: {
type: String,
default: '200px',
required: true
},
height: {
type: String,
default: '200px',
required: true
}
});
const options = {
tooltip: {
trigger: 'axis'
},
grid: {
left: '3%',
right: '4%',
top: '3%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value',
scale: true, //自适应
minInterval: 1 //最小间距
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
smooth: true
}
]
};
onMounted(() => {
// 图表初始化
const chart = echarts.init(document.getElementById(props.id) as HTMLDivElement);
chart.setOption(options);
// 大小自适应
window.addEventListener('resize', () => {
chart.resize();
});
});
</script>