From 99435df90dc63bbf9a3729826821fbd47677fb10 Mon Sep 17 00:00:00 2001 From: quanyawei <401863037@qq.com> Date: Wed, 13 Mar 2024 11:09:10 +0800 Subject: [PATCH] fix:监测因子相关性对比折线图修改和走航报告下载修改 --- src/components/Echarts/LineChartSpe.vue | 275 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 158 insertions(+), 117 deletions(-) diff --git a/src/components/Echarts/LineChartSpe.vue b/src/components/Echarts/LineChartSpe.vue index 74abf3e..fb1af0e 100644 --- a/src/components/Echarts/LineChartSpe.vue +++ b/src/components/Echarts/LineChartSpe.vue @@ -1,62 +1,65 @@ <template> <!-- <div> --> <!-- <div>1111111111111111111111111111111111111111</div> --> - <div :class="className" :style="{height:height,width:width}" /> + <div + :class="className" + :style="{ height: height, width: width }" + /> <!-- </div> --> </template> <script> -import echarts from 'echarts' -require('echarts/theme/macarons') // echarts theme -import resize from './mixins/resize' +import * as echarts from 'echarts' // echarts theme +// import resize from './mixins/resize' +require('echarts/theme/macarons') export default { - mixins: [resize], + // mixins: [resize], 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, - default: true + default: true, }, chartData: { type: Object, - required: true - } + required: true, + }, // xdata: { // type: Array, // required: true // } }, - data() { + data () { return { - chart: null + chart: null, } }, watch: { chartData: { - deep: true, - handler(val) { + handler (val) { this.setOptions(val) - } - } + }, + deep: true + }, }, - mounted() { + mounted () { this.$nextTick(() => { this.initChart() }) }, - beforeDestroy() { + beforeDestroy () { if (!this.chart) { return } @@ -64,108 +67,146 @@ this.chart = null }, methods: { - initChart() { + initChart () { this.chart = echarts.init(this.$el, 'macarons') + this.chart.clear() this.setOptions(this.chartData) }, - setOptions(val) { - console.log(val); - this.chart.setOption({ - xAxis: { - data: val.xAxis, - boundaryGap: false, - axisTick: { - show: false - } - }, - grid: { - left: 10, - right: 10, - bottom: 20, - top: 30, - containLabel: true - }, - toolbox: { - feature: { - dataZoom: { - yAxisIndex: 'none' - }, - restore: {}, - saveAsImage: {} - } - }, - // tooltip: { - // trigger: 'axis', - // position: function(pt) { - // return [pt[0], '10%'] - // } - // }, - tooltip: { - trigger: 'axis', - position: function(pt) { - return [pt[0], '10%'] - }, - formatter(params) { - for (let i = 0; i < params.length; i++) { - return params[i].seriesName + ':' + ' ' + params[i].data.data0 + setOptions (val) { + console.log('val,val', val) + // val.series.forEach(element => { + // element.data = element.data.map(item => item === 0 ? 0.1 : item) + // }) + let that = this + function fontSize (res) { + let clientWidth = + window.innerWidth || + document.documentElement.clientWidth || + document.body.clientWidth + if (!clientWidth) return + let fontSize = 100 * (clientWidth / 1920) + return res * fontSize + } + /** + * ���������������mouseover������������������������������ + * ������������������ ������������������������������������������������������������ + * ��������������������������������������������������������������������������� + * ������������������������series��������������������������������� + * ������params������������������������������ + */ + this.chart.on('mouseover', function (params) { + that.chart.setOption({ + series: [ + { + name: params.seriesName, + label: { + show: true, + fontSize: 16, + position: [10, -15], + formatter: '{c}' + } } - } + ] + }) + }) + // ���������������mouseout������������������������ + this.chart.on('mouseout', function (params) { + that.chart.setOption({ + series: [ + { + name: params.seriesName, + lineStyle: { + width: 2 + }, + label: { + show: false + }, + endLabel: { + show: false + } + } + ] + }) + }) + this.chart.setOption( + { + xAxis: { + data: val.xAxis, + boundaryGap: false, + axisTick: { + show: true, + }, + + }, + grid: { + left: '5%', + right: '5%', + top: '5%', + containLabel: true, + height: fontSize(4.3), + }, + tooltip: { + trigger: 'axis', + backgroundColor: 'rgba(50,50,50,0.5)', + textStyle: { + color: 'rgb(255, 255, 255);', + fontSize: fontSize(0.117), // ������������ + lineHeight: 0 + }, + formatter: function (params) { + console.log('params', params) + let html = params[0].name + params.forEach((item, index) => { + html += (`<br/>${item.marker + item.seriesName}: ${item.value === undefined ? 0 : item.value}`) + }) + return html + } + }, + yAxis: { + type: 'log', + axisTick: { + show: true, // ������������ + }, + axisLine: { + show: true, // ��������������������� + }, + // axisLabel: { + // formatter: function (value) { + // return value === 0.1 ? 0 : value + // } + // }, + }, + legend: { + data: val.title, + tooltip: { + show: true, + }, + textStyle: { + fontSize: fontSize(0.15), + }, + widht: 'auto', + height: 'auto', + top: fontSize(5.5), + }, + dataZoom: [ + { + type: 'inside', + start: 0, + end: 100, + }, + { + start: 0, + end: 10, + top: fontSize(4.5), + height: fontSize(0.4), + }, + ], + series: val.series }, - // tooltip: { - // trigger: 'axis', - // axisPointer: { - // type: 'cross' - // }, - // padding: [5, 10] - // }, - yAxis: { - axisLabel: { - show: false - } - }, - legend: { - icon: 'circle', - itemHeight: 15, - // textStyle: { - // fontSize: 18 - // }, - data: val.title - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100 - }, { - start: 0, - end: 10 - }], - series: val.series - // [{ - // name: JSON.parse(JSON.stringify(val.title)), - // itemStyle: { - // normal: { - // color: '#7AC5CD', - // lineStyle: { - // color: '#7AC5CD', - // width: 2 - // } - // } - // }, - // smooth: true, - // type: 'line', - // data: val.series, - // animationDuration: 2800, - // animationEasing: 'cubicInOut', - // areaStyle: {}, - // label: { - // normal: { - // show: true, - // position: 'top' - // } - // } - // }] - }, true) - } - } + true + ) + // window.onresize = this.chart.resize + }, + }, } </script> -- Gitblit v1.8.0