赞
踩
<template> <div style="width: 100%; height: 100%" ref="lineChart" class="heightclass"></div> </template> <script> import * as echarts from "echarts"; export default { props: { //x轴数据 XAxis: { type: Array, default: () => [] }, //y轴数据 YAxis: { type: Array, default: () => [] }, YAxis2: { type: Array, default: () => [] }, YAxis3: { type: Array, default: () => [] }, //名字 DataName: { type: String, }, //类型 typeName: { type: String, default: '降雨量' }, //刷新 refresh: { type: Number } }, data () { return { chart: null } }, mounted () { this.initChart(); window.addEventListener("resize", this.resizeChart); }, watch: { refresh () { if (this.chart) { this.chart.dispose(); this.chart = null; } this.initChart(); } }, methods: { //初始化图表 initChart () { this.chart = echarts.init(this.$refs.lineChart); let that = this let option = { color: ["#3398DB", "red", 'yellow'], tooltip: { trigger: 'axis', // formatter: function (params) { // let typeName = that.typeName // return `时间:${params[0].name}<br>${typeName}:${params[0].value}`; // }, axisPointer: { type: 'cross' }, textStyle: { color: '#fff', fontStyle: 'normal', fontFamily: '微软雅黑', fontSize: 12, }, backgroundColor: "transparent" }, legend: { data: ['温度(℃)', '降雨量(mm)', '风速(m/s)'], right: 10, textStyle: { color: '#fft' } }, title: { show: true, //显示策略,默认值true,可选为:true(显示) | false(隐藏) text: this.DataName, //主标题文本,'\n'指定换行 x: 'left', //水平安放位置,默认为'left',可选为:'center' | 'left' | 'right' | {number}(x坐标,单位px) textStyle: { //主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"} fontFamily: 'Arial, Verdana, sans...', fontSize: 25, fontStyle: 'normal', fontWeight: '700', color: "#fff" }, }, grid: { top: '10%', left: '6%', right: '3%', bottom: '5%', containLabel: true }, xAxis: [ { type: "category", data: this.XAxis, axisPointer: { type: "shadow", }, axisLabel: { show: true, color: "#3398DB", // 横坐标自定义展示 formatter: function (value) { if (value.length > 10) { value = value.substring(0, 11); } return value; }, }, axisLine: { lineStyle: { color: "#3398DB" }, }, }, ], yAxis: [ { type: "value", axisLabel: { show: true, color: "#3398DB" }, axisLine: { lineStyle: { color: "#3398DB", // 颜色 }, }, splitLine: { show: true, lineStyle: { color: 'rgba(61,91,98,0.8)', type: "dashed" } } } ], dataZoom: [ { type: "inside", //slider表示有滑动块的, show: true, xAxisIndex: [0], //表示x轴折叠 start: 1, //数据窗口范围的起始百分比,表示1% end: 100, //数据窗口范围的结束百分比,表示35%坐标 }, ], series: [ { name: '温度', type: "line", data: this.YAxis, }, { name: '降雨量', type: "line", data: this.YAxis2, }, { name: '风力风向', type: "line", data: this.YAxis3, } ] }; this.chart.setOption(option); }, resizeChart () { if (this.chart) { this.chart.resize(); } } } } </script> <style lang="scss" scoped> .heightclass { min-height: 276px; } </style>
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。