| | |
| | | <template> |
| | | <div :class="className" :style="{height:height,width:width}" /> |
| | | |
| | | <div :class="className" :style="{ height: height, width: width }" /> |
| | | </template> |
| | | |
| | | <script> |
| | | import echarts from 'echarts' |
| | | require('echarts/theme/macarons') // echarts theme |
| | | import echarts from "echarts"; |
| | | require("echarts/theme/macarons"); // echarts theme |
| | | /*import resize from './mixins/resize'*/ |
| | | |
| | | export default { |
| | |
| | | props: { |
| | | className: { |
| | | type: String, |
| | | default: 'chart' |
| | | default: "chart" |
| | | }, |
| | | width: { |
| | | type: String, |
| | | default: '100%' |
| | | default: "100%" |
| | | }, |
| | | height: { |
| | | type: String, |
| | | default: '350px' |
| | | default: "350px" |
| | | }, |
| | | autoResize: { |
| | | type: Boolean, |
| | |
| | | data() { |
| | | return { |
| | | chart: null |
| | | } |
| | | }; |
| | | }, |
| | | watch: { |
| | | chartData: { |
| | | deep: true, |
| | | handler(val) { |
| | | this.setOptions(val) |
| | | this.setOptions(val); |
| | | } |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.$nextTick(() => { |
| | | this.initChart() |
| | | }) |
| | | this.initChart(); |
| | | }); |
| | | }, |
| | | beforeDestroy() { |
| | | if (!this.chart) { |
| | | return |
| | | return; |
| | | } |
| | | this.chart.dispose() |
| | | this.chart = null |
| | | this.chart.dispose(); |
| | | this.chart = null; |
| | | }, |
| | | methods: { |
| | | initChart() { |
| | | this.chart = echarts.init(this.$el, 'macarons') |
| | | this.setOptions(this.chartData) |
| | | this.chart = echarts.init(this.$el, "macarons"); |
| | | this.setOptions(this.chartData); |
| | | }, |
| | | setOptions({ expectedData, actualData } = {}) { |
| | | this.chart.setOption({ |
| | | xAxis: { |
| | | data: ['04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00' , '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'], |
| | | data: [ |
| | | "04:00", |
| | | "05:00", |
| | | "06:00", |
| | | "07:00", |
| | | "08:00", |
| | | "09:00", |
| | | "10:00", |
| | | "11:00", |
| | | "12:00", |
| | | "13:00", |
| | | "14:00", |
| | | "15:00", |
| | | "16:00", |
| | | "17:00", |
| | | "18:00", |
| | | "19:00", |
| | | "20:00", |
| | | "21:00", |
| | | "22:00", |
| | | "23:00" |
| | | ], |
| | | boundaryGap: false, |
| | | axisTick: { |
| | | show: false |
| | |
| | | containLabel: true |
| | | }, |
| | | tooltip: { |
| | | trigger: 'axis', |
| | | trigger: "axis", |
| | | axisPointer: { |
| | | type: 'cross' |
| | | type: "cross" |
| | | }, |
| | | padding: [5, 10] |
| | | }, |
| | |
| | | } |
| | | }, |
| | | legend: { |
| | | data: ['预警值','限值'] |
| | | data: ["预警值", "限值"], |
| | | textStyle: { |
| | | color: "#fff" |
| | | } |
| | | }, |
| | | series: [{ |
| | | name: '预警值', itemStyle: { |
| | | normal: { |
| | | color: '#FF005A', |
| | | lineStyle: { |
| | | color: '#FF005A', |
| | | width: 2, |
| | | |
| | | }, |
| | | |
| | | } |
| | | }, |
| | | smooth: true, |
| | | type: 'line', |
| | | data:[200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200], |
| | | animationDuration: 1000, |
| | | animationEasing: 'cubicInOut' |
| | | }, |
| | | series: [ |
| | | { |
| | | name: '限值', |
| | | smooth: true, |
| | | type: 'line', |
| | | name: "预警值", |
| | | itemStyle: { |
| | | normal: { |
| | | color: '#3888fa', |
| | | color: "#FF005A", |
| | | lineStyle: { |
| | | color: '#3888fa', |
| | | color: "#FF005A", |
| | | width: 2 |
| | | }, |
| | | areaStyle: { |
| | | color: '#f3f8ff' |
| | | } |
| | | } |
| | | }, |
| | | data:[200, 200, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181, 224,210, 172, 181], |
| | | smooth: true, |
| | | type: "line", |
| | | data: [ |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200, |
| | | 200 |
| | | ], |
| | | animationDuration: 1000, |
| | | animationEasing: "cubicInOut" |
| | | }, |
| | | { |
| | | name: "限值", |
| | | smooth: true, |
| | | type: "line", |
| | | itemStyle: { |
| | | normal: { |
| | | color: "#3888fa", |
| | | lineStyle: { |
| | | color: "#3888fa", |
| | | width: 2 |
| | | }, |
| | | areaStyle: { |
| | | color: "#f3f8ff" |
| | | } |
| | | } |
| | | }, |
| | | data: [ |
| | | 200, |
| | | 200, |
| | | 181, |
| | | 224, |
| | | 210, |
| | | 172, |
| | | 181, |
| | | 224, |
| | | 210, |
| | | 172, |
| | | 181, |
| | | 224, |
| | | 210, |
| | | 172, |
| | | 181, |
| | | 224, |
| | | 210, |
| | | 172, |
| | | 181, |
| | | 224, |
| | | 210, |
| | | 172, |
| | | 181 |
| | | ], |
| | | animationDuration: 800, |
| | | animationEasing: 'quadraticOut' |
| | | }] |
| | | }) |
| | | animationEasing: "quadraticOut" |
| | | } |
| | | ] |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | </script> |