前端.map的使用

子组件传值的使用,直接附源码吧,有.map示例

<template>
  <a-card :body-style="{ padding: '10px' }" :head-style="{ padding: '0 10px' }" title="收入分析图" :bordered="false"
    class="card-border-radius">
    <!-- {{dayValue}} -->
    <div class="chart-item-container">
      <a-skeleton animation v-if="loading">
        <a-skeleton-line :rows="4" />
      </a-skeleton>
      <template v-else>
        <div ref="payOrderCountChart" class="chart-item"></div>
      </template>
    </div>
  </a-card>
</template>
<script lang="ts">
import useEcharts from '@/hooks/useEcharts'
import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, toRefs, reactive } from 'vue'
import { dispose, graphic } from 'echarts/core'
//日期数组
var months = ref([])
// var months = [202201, 202202]


export default defineComponent({
  name: 'PayOrderCountChart',
  props: {
    dayValue: Array
  },

  setup(props) {
    const loading = ref(false)
    const payOrderCountChart = ref<HTMLDivElement | null>(null)
    let interval: any = null
    const data = toRefs(props)
    var organAcqId = data.dayValue.value
    // console.log(organAcqId?.map(o => { return [o.crtDay].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.daySuccCount].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.dayFailAcct].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.dayRefundAcct].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.dayRecepitAcct].toString() }), '-------------------')

    // console.log(organAcqId?.map(o => { return [o.dayTotalCount].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.daySuccCount].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.dayFailCount].toString() }), '-------------------')
    // console.log(organAcqId?.map(o => { return [o.dayRecepitAcct].toString() }), '-------------------')

    months = organAcqId?.map(o => { return [o.crtDay].toString() })



    const init = () => {
      const option = {
        color: ['rgba(64, 58, 255)'],
        legend: {
          icon: 'rect',
          itemWidth: 30,  // 设置宽度
          itemHeight: 4, // 设置高度
          itemGap: 24, // 设置间距
          data: ['实际收入金额', '支付失败金额', '退款金额'],
          textStyle: {
            //文字样式
            color: '#00000',
            fontSize: '12'
          },
          right: '30%'
        },
        dataZoom: {
        show: true, // 为true 滚动条出现
        realtime: true,  
        type:'slider', // 有type这个属性,滚动条在最下面,也可以不行,写y:36,这表示距离顶端36px,一般就是在图上面。
        height: 20, // 表示滚动条的高度,也就是粗细
        start: 20, // 表示默认展示20%~80%这一段。
        end: 80
        },
        grid: {
          top: '10%',
          left: '2%',
          right: '2%',
          bottom: '5%',
          containLabel: true,
        },

        tooltip: {
          trigger: 'axis',
        },
        xAxis: {
          type: 'category',
          data: months,
        },
        yAxis: {
          type: 'value',
          max: 5000,
        },
        series: [
          {
            name: '实际收入金额',
            type: 'bar',
            barWidth: '5%',
            data: organAcqId?.map(o => { return [o.daySuccCount].toString()}).map(Number).map(o=>o/100)
          },
          {
            name: '支付失败金额',
            type: 'bar',
            barWidth: '20%',
            data: organAcqId?.map(o => { return [o.dayFailAcct].toString() }).map(Number).map(o=>o/100)
          },
          {
            name: '退款金额',
            type: 'bar',
            barWidth: '5%',
            data: organAcqId?.map(o => { return [o.dayRefundAcct].toString() }).map(Number).map(o=>o/100)
          }

        ],
        color: ['#3c5fff', '#e53e3b', '#d1dca9'],

        // dataZoom: {
        //   xAxisIndex: [0],
        // show: true, // 为true 滚动条出现
        // realtime: true,  
        // type:'slider', // 有type这个属性,滚动条在最下面,也可以不行,写y:36,这表示距离顶端36px,一般就是在图上面。
        // height: 20, // 表示滚动条的高度,也就是粗细
        // start: 1, // 表示默认展示20%~80%这一段。
        // end: 80
        // }



      }


      setTimeout(() => {
        loading.value = false
        setTimeout(() => {
          nextTick(() => useEcharts(payOrderCountChart.value as HTMLDivElement).setOption(option))
        }, 100)
      }, 100)
    }
    const updateChart = () => {
      useEcharts(payOrderCountChart.value as HTMLDivElement).resize()
    }
    onMounted(init)
    onBeforeUnmount(() => {
      dispose(payOrderCountChart.value as HTMLDivElement)
      // clearInterval(interval)
    })
    return {
      loading,
      payOrderCountChart,
      updateChart,
    }
  },
})
</script>

<style lang="less" scoped>
.chart-item-container {
  width: 100%;

  .chart-item {
    height: 30vh;
  }
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

庞胖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值