| | |
| | | <template> |
| | | <div class="chart-wrap"> |
| | | <div ref="lineChart" class="line-chart"></div> |
| | | <div |
| | | ref="lineChart" |
| | | class="line-chart" |
| | | :style="'height:' + chartHeight + ';'" |
| | | ></div> |
| | | </div> |
| | | </template> |
| | | <script> |
| | | import * as echarts from 'echarts'; |
| | | import { smallLineOption } from '@/utils/chart/chart-option'; |
| | | import { smallLineOption, baseVisualMap } from '@/utils/chart/chart-option'; |
| | | |
| | | export default { |
| | | props: { |
| | |
| | | // series: [] |
| | | // }; |
| | | // } |
| | | } |
| | | }, |
| | | // 折线图展示高度 |
| | | chartHeight: { |
| | | type: String, |
| | | default: '140px' |
| | | }, |
| | | // 折线图Y轴刻度间距 |
| | | yMinInterval: { |
| | | type: Number, |
| | | default: 1 |
| | | }, |
| | | // 异常数据索引范围集合,[[i1,i2], [i3,i4],...] |
| | | exceptionIndexArr: Array |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | refreshChart() { |
| | | const { xAxis, series } = this.modelValue; |
| | | if (!this.option) { |
| | | this.option = smallLineOption(xAxis, series); |
| | | this.option = smallLineOption(xAxis, series, this.yMinInterval); |
| | | if (this.exceptionIndexArr) { |
| | | const visualMap = baseVisualMap(this.exceptionIndexArr); |
| | | this.option.visualMap = visualMap; |
| | | } |
| | | } else { |
| | | this.option.xAxis[0].data = xAxis; |
| | | this.option.series = series; |
| | | } |
| | | if (this.lineChart) { |
| | | this.lineChart.setOption(this.option, { notMerge: true }); |
| | | // console.log('折线图生成:立即'); |
| | | } else { |
| | | this.onChartCreated = () => { |
| | | this.lineChart.setOption(this.option, { notMerge: true }); |
| | |
| | | }, |
| | | mounted() { |
| | | this.lineChart = echarts.init(this.$refs.lineChart); |
| | | if (typeof this.onChartCreated === 'function') { |
| | | this.onChartCreated(); |
| | | } |
| | | this.onChartCreated(); |
| | | // setTimeout(() => { |
| | | // if (typeof this.onChartCreated === 'function') { |
| | | // this.onChartCreated(); |
| | | // // console.log('折线图生成:滞后'); |
| | | // } |
| | | // }, 500); |
| | | } |
| | | }; |
| | | </script> |
| | |
| | | justify-content: center; |
| | | } |
| | | .line-chart { |
| | | width: 300px; |
| | | height: 140px; |
| | | width: 318px; |
| | | /* height: 140px; */ |
| | | /* border-bottom: 1px solid rgba(255, 255, 255, 0.329); */ |
| | | } |
| | | </style> |