| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <div ref="work" class="work-box"></div>
- </template>
- <script lang="ts" setup>
- import * as echarts from 'echarts';
- import { ref, nextTick, watch, defineProps } from 'vue';
- let props = defineProps<{
- xData: string[];
- y1Data: number[];
- y2Data: number[];
- y3Data: number[];
- y4Data: number[];
- yUnit?: string;
- }>();
- //获取dom元素节点
- let work = ref<any>();
- watch(
- () => props.xData,
- () => {
- getOption();
- },
- { immediate: true, deep: true }
- );
- function getOption() {
- nextTick(() => {
- const myChart = echarts.init(work.value);
- let option = {
- tooltip: {
- trigger: 'item',
- backgroundColor: 'rgba(0, 0, 0, .6)',
- textStyle: {
- color: '#fff',
- fontSize: 12,
- },
- },
- grid: {
- top: '15%',
- left: '10%',
- bottom: '10%',
- right: '2%',
- },
- legend: {
- align: 'left',
- top: '0%',
- type: 'plain',
- textStyle: {
- color: '#7ec7ff',
- fontSize: 14,
- },
- itemGap: 10,
- itemWidth: 5,
- },
- xAxis: [
- {
- type: 'category',
- axisLabel: {
- textStyle: {
- color: '#b3b8cc',
- },
- },
- // axisLine: {
- // lineStyle: {
- // color: '#244a94',
- // },
- // },
- splitLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- data: props.xData,
- },
- ],
- yAxis: [
- {
- // boundaryGap: false,
- axisLabel: {
- textStyle: {
- color: '#b3b8cc',
- },
- },
- name: props.yUnit,
- // nameTextStyle: {
- // color: '#fff',
- // fontSize: 12,
- // lineHeight: 10,
- // },
- splitLine: {
- lineStyle: {
- color: '#0d2973',
- },
- },
- axisTick: {
- show: false,
- },
- },
- ],
- series: [
- {
- name: '平均值',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 4,
- lineStyle: {
- normal: {
- width: 2,
- },
- },
- data: props.y1Data,
- },
- {
- name: '最大值',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 4,
- lineStyle: {
- normal: {
- width: 2,
- },
- },
- data: props.y2Data,
- },
- {
- name: '最小值',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 4,
- lineStyle: {
- normal: {
- width: 2,
- },
- },
- data: props.y3Data,
- },
- {
- name: '实时值',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 4,
- lineStyle: {
- normal: {
- width: 2,
- },
- },
- data: props.y4Data,
- },
- ],
- };
- myChart.setOption(option);
- window.onresize = function () {
- myChart.resize();
- };
- });
- }
- </script>
- <style scoped lang="less">
- .work-box {
- width: 100%;
- height: 100%;
- }
- </style>
|