123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <template>
- <div ref="chart" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- import * as echarts from 'echarts'
- export default {
- name: 'OrderTrendChart',
- props: {
- data: {
- type: Array,
- default: () => []
- }
- },
- data() {
- return {
- chart: null
- }
- },
- watch: {
- data: {
- handler(val) {
- this.initChart()
- },
- deep: true
- }
- },
- mounted() {
- this.initChart()
- window.addEventListener('resize', this.resizeChart)
- },
- beforeDestroy() {
- if (this.chart) {
- this.chart.dispose()
- }
- window.removeEventListener('resize', this.resizeChart)
- },
- methods: {
- initChart() {
- if (!this.chart) {
- this.chart = echarts.init(this.$refs.chart)
- }
-
- const option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross',
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- data: ['洗衣金额','实付金额']
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: this.data.map(item => item.statisticsDate)
- },
- yAxis: {
- type: 'value',
- name: '金额',
- axisLabel: {
- formatter: '{value} 元'
- }
- },
- series: [
- {
- name: '洗衣金额',
- type: 'line',
- stack: 'Total',
- areaStyle: {
- opacity: 0.3
- },
- emphasis: {
- focus: 'series'
- },
- data: this.data.map(item => item.clothOrderAmount || 0)
- },
- {
- name: '实付金额',
- type: 'line',
- stack: 'Total',
- areaStyle: {
- opacity: 0.3
- },
- emphasis: {
- focus: 'series'
- },
- data: this.data.map(item => item.clothReceiveAmount || 0)
- }
- ]
- }
-
- this.chart.setOption(option)
- },
- resizeChart() {
- if (this.chart) {
- this.chart.resize()
- }
- }
- }
- }
- </script>
|