123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <template>
- <div class="echart-work">
- <div ref="work" class="work-box"></div>
- </div>
- </template>
-
- <script lang="ts" setup>
- import * as echarts from 'echarts'
- import { ref, nextTick,reactive, watch, defineProps } from 'vue';
- let props = defineProps({
- echartDataWd: {
- type: Object,
- }
- })
- //获取dom元素节点
- let work = ref<any>()
- let echartDataWds=reactive({})
- watch(() => props.echartDataWd, (data) => {
- echartDataWds=Object.assign({},data)
- getOption()
- }, { immediate: true ,deep:true})
- function getOption() {
- nextTick(() => {
- const myChart = echarts.init(work.value)
- let option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross',
- },
- },
- legend: {
- align: 'left',
- right: '5%',
- top: '5%',
- type: 'plain',
- textStyle: {
- color: '#7ec7ff',
- fontSize: 14,
- },
- // icon:'rect',
- itemGap: 25,
- itemWidth: 18,
- icon: 'path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z',
- data: [
- {
- name: '最小值',
- },
- {
- name: '最大值',
- },
- {
- name: '平均值',
- },
- ],
- },
- grid: {
- top: '20%',
- left: '4%',
- right: '4%',
- bottom: '20%',
- // containLabel: true
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: false,
- axisLine: {
- //坐标轴轴线相关设置。数学上的x轴
- show: true,
- lineStyle: {
- color: '#244a94',
- },
- },
- axisLabel: {
- //坐标轴刻度标签的相关设置
- textStyle: {
- color: '#b3b8cc',
- padding: 5,
- fontSize: 14,
- },
- formatter: function (data) {
- return data
- },
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: '#0d2973',
- type: 'dashed',
- },
- },
- axisTick: {
- show: false,
- },
- data: echartDataWds.xData,
- },
- ],
- yAxis: [
- {
- name: '(℃)',
- nameTextStyle: {
- color: '#7ec7ff',
- fontSize: 14,
- padding: 0,
- },
- min: 0,
- max: 2000,
- splitLine: {
- show: true,
- lineStyle: {
- color: '#0d2973',
- type: 'dashed',
- },
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: '#244a94',
- },
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#b3b8cc',
- padding: 5,
- },
- formatter: function (value) {
- if (value === 0) {
- return value
- }
- return value
- },
- },
- axisTick: {
- show: false,
- },
- },
- ],
- series: [
- {
- name:echartDataWds.maxData ? echartDataWds.maxData.lengedData : '',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 8,
- lineStyle: {
- normal: {
- width: 2,
- color: '#4653fd', // 线条颜色
- },
- borderColor: 'rgba(0,0,0,.4)',
- },
- itemStyle: {
- color: '#4653fd',
- borderColor: '#646ace',
- borderWidth: 0,
- },
- data: echartDataWds.maxData ? echartDataWds.maxData.data : [],
- },
- {
- name: echartDataWds.minData ? echartDataWds.minData.lengedData : '',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 8,
- lineStyle: {
- normal: {
- width: 2,
- color: '#46fda8', // 线条颜色
- },
- borderColor: 'rgba(0,0,0,.4)',
- },
- itemStyle: {
- color: '#46fda8',
- borderColor: '#646ace',
- borderWidth: 0,
- },
- data: echartDataWds.minData ? echartDataWds.minData.data : [],
- },
- {
- name: echartDataWds.aveaData ? echartDataWds.aveaData.lengedData : '',
- type: 'line',
- smooth: true,
- yAxisIndex: 0,
- symbolSize: 8,
- lineStyle: {
- normal: {
- width: 2,
- color: '#1eb0fc', // 线条颜色
- },
- borderColor: 'rgba(0,0,0,.4)',
- },
- itemStyle: {
- color: '#1eb0fc',
- borderColor: '#646ace',
- borderWidth: 0,
- },
- data: echartDataWds.aveaData ? echartDataWds.aveaData.data : [],
- },
- ],
- }
- myChart.setOption(option)
- window.onresize = function () {
- myChart.resize()
- }
- })
- }
- </script>
-
- <style scoped lang="less">
- .echart-work {
- width: 100%;
- height: 100%;
- .work-box {
- width: 100%;
- height: 100%;
- }
- }
- </style>
-
|