quanyawei
2024-06-17 afb9e7c8c9865be6a73d19e35819b5aa6b8afbdd
src/components/Echarts/LineChartSpe.vue
@@ -1,17 +1,20 @@
<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 * as 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,
@@ -38,25 +41,25 @@
    //   required: true
    // }
  },
  data() {
  data () {
    return {
      chart: null,
    }
  },
  watch: {
    chartData: {
      handler(val) {
      handler (val) {
        this.setOptions(val)
      },
      deep: true
    },
  },
  mounted() {
  mounted () {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
  beforeDestroy () {
    if (!this.chart) {
      return
    }
@@ -64,14 +67,21 @@
    this.chart = null
  },
  methods: {
    initChart() {
    initChart () {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.clear()
      this.setOptions(this.chartData)
      // this.setOptions(this.chartData)
    },
    setOptions(val) {
    setOptions (val) {
      console.log('val,val', val)
      // val.series.forEach(element => {
      //   element.data = element.data.map(item => item === 0 ? 0.1 : item)
      // })
      if (this.chart) {
        this.chart.clear()
      }
      let that = this
      function fontSize(res) {
      function fontSize (res) {
        let clientWidth =
          window.innerWidth ||
          document.documentElement.clientWidth ||
@@ -147,17 +157,7 @@
              lineHeight: 0
            }
          },
          yAxis: {
            axisTick: {
              show: true, // 轴线刻度
            },
            axisLine: {
              show: true, //不显示坐标轴线
            },
            axisLabel: {
              show: true, //不显示坐标轴上的文字
            }
          },
          yAxis: val.yAxis,
          legend: {
            data: val.title,
            tooltip: {
@@ -187,7 +187,7 @@
        },
        true
      )
      window.onresize = this.chart.resize
      // window.onresize = this.chart.resize
    },
  },
}