echarts 根据选择时段来动态渲染折线图和统计

接口返回数据:

[{"TypeName":"费用1","x_data":[0,0,0,0,0.0100,0,0],"total":0.0100},{"TypeName":"费用2","x_data":[0,0,0,0,0,0,0],"total":0},{"TypeName":"费用3","x_data":[0,0,0,0,0,0,0],"total":0},{"y_time":["2021-07-02","2021-07-03","2021-07-04","2021-07-05","2021-07-06","2021-07-07","2021-07-08"]}]

页面效果:
在这里插入图片描述

在这里插入图片描述
子组件mutiLine :

<template>
  <div class="hello">
    <div id="myCharts" style="width:50.1%;height: 340px;float: left;margin: 0.5rem 0.5rem 0 0;"></div>
    <div id="mytwoCharts" style="width:49%;height: 340px;float: left;margin: 0.5rem 0.2rem 0 0;"></div>
    <div id="BINCharts" style="width:48.9%;height: 320px;float: right;margin-top: 2rem;"></div>
    <div id="mythreeCharts" style="width:50.2%;height: 340px;float: left;margin-top: 0.5rem;"></div>
  </div>
</template>


<script>
import * as echarts from 'echarts';
export default {
     
  name: 'mutiLine',
  data(){
     
    return {
     
      series: [],
      legnData: [],
      bin_series:[],
      interval: [],//为了进行分割x轴
    }
  },
  props:{
     
    lineData:Array,
    lineTime:Array,
  },
   //折线数据通过变量传递
  watch: {
     
    lineData: {
     
      deep: true,
      handler(val) {
     
        if (val) {
     
          setTimeout(this.initEcharts(), 100);
          setTimeout(this.inittwoEcharts(), 100);
          setTimeout(this.initthreeEcharts(), 100);
          setTimeout(this.BINinitEcharts(), 100);
        }
      }
    },
  },
  mounted () {
     
    this.getZheData();
    this.initEcharts();
    this.inittwoEcharts();
    this.initthreeEcharts();
    this.BINinitEcharts();

  },
  methods: {
     


    //循环存储数据
    getZheData(){
     
      for(let i = 0;i < this.lineData.length;i++){
     
        this.interval.push(this.lineData[i].x_data)
        this.legnData.push(this.lineData[i].TypeName)
        this.bin_series.push({
     
          value:this.lineData[i].total,
          name:this.lineData[i].TypeName,
        })
        this.series.push({
     
          name: this.lineData[i].TypeName,
          data: this.lineData[i].x_data,
          type: 'line',
          smooth: true,
          itemStyle: {
     
            //则线图每个点的样式
            borderWidth: 10,
          },
        })
      }
    },

    //折线图1
    initEcharts: function () {
     
      const Charts = document.getElementById('myCharts');//getDom
      const myCharts = echarts.init(Charts);// add
      let series = [];
      let legnData = [
  • 2
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值