美文网首页
vue+elementUi+echarts 折线图组件

vue+elementUi+echarts 折线图组件

作者: 小李疯狂输出 | 来源:发表于2020-07-22 16:18 被阅读0次

    echarts官网

    效果

    🍕 此图并非折线图饼图联动 折线图饼图联动组件飞机票

    🥟饼图点击事件再饼图组件中 饼图组件飞机票

    🍗主要看折线图部分,动态变化折现条数


    录制1.gif

    折线图组件 mutiLine.vue

    <template>
      <div :class="className" :id="id" :style="{height:height,width:width}"></div>
    </template>
    
    <script>
    import echarts from 'echarts'
    import { debounce } from '@/utils'
    require('echarts/theme/macarons') // echarts theme
    export default {
      props: {
        lineData: {
          type: Object,
          default: {}
        },
        className: {
          type: String,
          default: 'chart'
        },
        id: {
          type: String,
          default: 'chart'
        },
        width: {
          type: String,
          default: '100%'
        },
        height: {
          type: String,
          default: '420px'
        },
        autoResize: {
          type: Boolean,
          default: true
        },
      },
      data() {
        return {
          chart: null
        }
      },
      mounted() {
        this.$nextTick(function () {
          setTimeout(this.initChart(), 200);
        })
      },
      methods: {
        initChart() {
          this.chart = echarts.init(document.getElementById(this.id), 'macarons')
          this.chart.clear();//清除画布内容
          this.chart.setOption({
            backgroundColor: '#ffffff',
            title: {
              text: '', //标题
            },
            tooltip: {
              trigger: 'axis'
            },
            legend: {
              top: 0,
              icon: 'rect',
              itemWidth: 14,
              itemHeight: 5,
              itemGap: 13,
              data: this.lineData.yData, //导航数据
              right: '50%',
              textStyle: {
                fontSize: 12,
                color: '#000000'
              }
            },
            grid: {
              top: 100,
              left: '3%',
              right: '4%',
              bottom: '2%',
              containLabel: true
            },
            xAxis: [{
              type: 'category',
              boundaryGap: false,
              axisLine: {
                lineStyle: {
                  color: '#008acd'
                }
              },
              data: this.lineData.yData,
            }],
            yAxis: [{
              type: 'value',
              name: '',
              axisTick: {
                show: false
              },
              axisLine: {
                lineStyle: {
                  color: '#008acd'
                }
              },
              axisLabel: {
                margin: 10,
                textStyle: {
                  fontSize: 14
                }
              },
              splitLine: {
                lineStyle: {
                  color: '#eeeeee'
                }
              }
            }],
            series: this.lineData.series
          })
        }
      },
    //折现数据通过变量传递
      watch: {
        lineData: {
          deep: true,
          handler(val) {
            console.log('折线图监听', val)
            if (val) {
              setTimeout(this.initChart(), 100);
            }
          }
        },
      }
    }
    </script>
    

    父组件引用

    <muti-line :lineData="lineData"></muti-line>
    
    import mutiLine from "@/components/Charts/mutiLine";
    export default{
      components:{ mutiLine }
    }
    data(){
      return{ lineData:{} }
    }
    

    相关文章

      网友评论

          本文标题:vue+elementUi+echarts 折线图组件

          本文链接:https://www.haomeiwen.com/subject/dwlzkktx.html