LineCharts.vue 1.25 KB
<template>
    <div :id="domId" style="width: 100%" :style="{ height }"></div>
  </template>
  
  <script type="text/ecmascript-6">
  import * as echarts from 'echarts'
  import getLineOptions from './LineOptions'
  export default {
    name: 'LineCharts',
    props: {
      height: {
        type: String
      },
      dataList: {
        type: Array,
        default: () => []
      },
      domId: {
        type: String,
        default: 'line'
      },
      tooltipFormatterObj: {
        type: Array,
        default: () => {}
      },
      valName: {
        type: String,
        default: 'val'
      }
    },
    data() {
      return {}
    },
  
    mounted() {
      this.barLineDom = document.getElementById(this.domId)
      this[this.domId] = echarts.init(this.barLineDom)
      this.chartBindEvent()
      this.drawBarLine()
    },
  
    methods: {
      drawBarLine() {
        console.log(this.dataList);
        this.barLineOptions = getLineOptions()
        this.barLineOptions.series[0].data = this.dataList.map(item => item.val)
      },
      chartBindEvent() {
        // resize
        window.addEventListener('resize', () => {
          this[this.domId].resize()
        })
      }
    }
  }
  </script>
  
  <style lang="scss" scoped></style>