Newer
Older
KaiFengPC / src / views / project / compensation / homeEcharts / project.vue
@zhangdeliang zhangdeliang on 23 May 3 KB 初始化项目
<template>
    <div ref="assetEchart" class="asset_echart"></div>
  </template>
  <script lang="ts" setup>
  import { init } from "echarts";
  import  * as echarts from 'echarts'
  import {
    reactive,
    toRefs,
    Ref,
    ref,
    onMounted,
    watchEffect,
    defineProps,
  } from "vue";
  const assetEchart: Ref<HTMLElement | null | any> = ref(null);
  let {
    data: { type, xData,yData, center, padding, itemStyle,x ,y},
  } = defineProps(["data"]);
  console.log("x11Data", xData)
  let arrayist=[]
  xData.forEach((i,x)=>{ 
    arrayist.push(x)
  })
// var salvProName =["安徽省","河南省","浙江省","湖北省","贵州省","江西省","江苏省","四川省","云南省","湖南省"];
// var salvProValue =[239,181,154,144,135,117,74,72,67,55];
var salvProMax =[];//背景按最大值
for (let i = 0; i < yData.length; i++) {
    salvProMax.push(yData[0])
}
  const initM = () => {
    const chart = init(assetEchart.value as HTMLElement);
    window.addEventListener("resize", () => {
      chart.resize();
    });
    chart.setOption( {
    grid: {
        left: '2%',
        right: '2%',
        bottom: '2%',
        top: '9%',
        containLabel: true
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'none'
        },
        formatter: function(params) {
            return params[0].name  + ' : ' + params[0].value
        }
    },
    xAxis: {
        show: false,
        type: 'value'
    },
    yAxis: [{
        type: 'category',
        inverse: true,
        axisLabel: {
            show: true,
            textStyle: {
                color: '#fff'
            },
        },
        splitLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLine: {
            show: false
        },
        data: xData
    }, {
        type: 'category',
        inverse: true,
        axisTick: 'none',
        axisLine: 'none',
        show: true,
        axisLabel: {
            textStyle: {
                color: '#ffffff',
                fontSize: '12'
            },
        },
        data:yData
    }],
    series: [{
            name: '值',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    barBorderRadius: 30,
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: 'rgb(57,89,255,1)'
                    }, {
                        offset: 1,
                        color: 'rgb(46,200,207,1)'
                    }]),
                },
            },
            barWidth: 20,
            data: yData
        },
        {
            name: '背景',
            type: 'bar',
            barWidth: 20,
            barGap: '-100%',
            data: salvProMax,
            itemStyle: {
                normal: {
                    color: 'rgba(24,31,68,1)',
                    barBorderRadius: 30,
                }
            },
        },
    ]
});
  };
  function chartSize(container, charts) {
    function getStyle(el, name) {
      if (window.getComputedStyle) {
        return window.getComputedStyle(el, null);
      } else {
        return el.currentStyle;
      }
    }
    const hi = getStyle(container, "height").height;
    charts.style.height = hi;
  }
  watchEffect(() => {});
  onMounted(() => {
    initM();
  });
  </script>
  
  <style lang="scss" scoped>
  .asset_echart {
    width: 498px;
    height: 250px;
    margin: 10px 14px 0 16px;
  
    &_echart {
      width: 100%;
      height: 100%;
    }
  }
  </style>