echarts 折线图加阴影

在这里插入图片描述

父组件:
<lineChartIncome :opt="tradeIncome" />

import lineChartIncome from "./components/lineChartIncome";

data() {
	return {
		tradeIncome: {
	        seriesData: [[20, 14, 17,30,24], [12, 14, 15,40,50]],
	        xData: ['2019', '2020', '2021', '2022', '2023'],
	        legend: ['年营业收入', '完成收款额']
	      }
	}
}
子组件:
<template>
  <div style="width: 100%;height: 100%;">
    <ChartPanel ref="chart" :option="options" :style="opt.yAxisName ? 'height:calc(100% - 16px)' : ''"></ChartPanel>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import ChartPanel from '@/components/ChartPanel';
export default {
  components: {
    ChartPanel
  },
  props: {
    opt: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      options: null
    }
  },
  watch: {
    opt: {
      deep: true,
      immediate: true,
      handler(val) {
        // if (val && val.seriesData) {
        this.getOpt(val)
        // }
      }
    }
  },
  methods: {
    getOpt(val) {
      let {
        seriesData,
        xData,
        legend
      } = val
      this.options = {
        title: {
          text: '年营业收入',
          x: 'left',
          y: 0,
          textStyle: {
            color: 'rgba(35, 35, 56, 1)',
            fontSize: 16,
            fontWeight: '700',
          },
        },
        legend: {
          data: legend,
          align: 'left',
          right: '0',
          top: 2,
          textStyle: {
            color: "#595D64",
            fontSize: 14
          }
        },
        grid: {
          left: '0',
          right: '16',
          top: 45,
          bottom: '0',
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          formatter: params => {
            let result = `<div style="font-weight:700">${params[0].name}年</div>`
            params.forEach(ele => {
              result += `<div>${ele.seriesName}
                        <span style="color:${ele.color};font-weight:700">${ele.value}万元</span>  
                      </div>`
            });
            return result
          }
        },
        xAxis: [{
          type: 'category',
          data: xData,
          splitArea: {
            color: '#f00',
            lineStyle: {
              color: '#f00'
            },
          },
          axisLabel: {
            textStyle: {
              color: "#595D64",
              fontSize: 14,
            }
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: '#E1E5ED',
              type: 'dashed'
            }
          },
          boundaryGap: false,
        }],
        yAxis: [{
          type: 'value',
          axisLabel: {
            formatter: value => {
              return value + ''
            },
            show: true,
            textStyle: {
              color: "#595D64",
              fontSize: 14,
            },
          },
          splitLine: {
            // show: false,
            lineStyle: {
              color: '#E1E5ED',
              type: 'dashed'
            }
          }
        }],
        series: [{
          name: legend[0],
          type: 'line',
          data: seriesData[0],
          smooth: true,
          lineStyle: {
            width: 2,
            color: '#3562D4',
            shadowColor: '#3562D4',
            shadowBlur: 4,
            shadowOffsetY: 6
          },
          itemStyle: {
            normal: {
              color: '#3562D4',
              borderColor: '#3562D4'
            }
          },
        }, {
          name: legend[1],
          type: 'line',
          data: seriesData[1],
          smooth: true,
          lineStyle: {
            width: 2,
            color: '#34BF66',
            shadowColor: '#34BF66',
            shadowBlur: 4,
            shadowOffsetY: 6
          },
          itemStyle: {
            normal: {
              color: '#34BF66',
              borderColor: '#34BF66'
            }
          }
        },
        ]
      };
      this.$nextTick(() => {
        this.$refs.chart.initChart(echarts, chart => {
          // chart.setOption(this.options)
          this.options && chart.setOption(this.options, true);
        });
      })
    }
  }
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值