• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

vue echarts实现横向柱状图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文实例为大家分享了vue echarts实现横向柱状图的具体代码,供大家参考,具体内容如下

实现效果:

代码:

<template>
  <div class="OverYearsPompany">
    <div id="OverYearsPompanyChart" style="flex: 1; height: 368px; margin-top: -42px"></div>
  </div>
</template>
<script>
import { getProposedInvestments } from '@/api/government';
const colors = [
  ['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
  ['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
  ['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
  ['rgba(240, 7, 100, 1)', 'rgba(0, 215, 229, 1)'],
];
export default {
  data() {
    return {
      investmentsWayData: [],
      investmentsWayDataCount: [],
      investmentsWayDataCounts: [],
    };
  },
  mounted() {
    this.getProposedInvestments();
  },
  methods: {
    initMap() {
      var myChart = this.$echarts.init(document.getElementById('OverYearsPompanyChart'));
      const option = {
        tooltip: {
          show: true,
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        xAxis: {
          type: 'value',
          axisLabel: {
            show: true,
            color: '#02CFFCFF',
            fontFamily: 'TencentSans',
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#02CFFCFF',
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: 'rgba(71, 126, 171, 1)',
            },
          },
        },
        yAxis: [
          {
            type: 'category',
            inverse: true, //倒叙
            axisLabel: {
              color: '#02CFFCFF',
              fontFamily: 'TencentSans',
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#02CFFCFF',
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                type: 'dotted',
                color: 'rgba(71, 126, 171, 1)',
              },
            },
            data: this.investmentsWayData,
          },
        ],
        series: [
          {
            type: 'bar',
            barWidth: 15,
            label: {
              position: ['98%', -20],
              show: true,
              color: '#fff',
              fontFamily: 'TencentSans',
            },
            data: this.investmentsWayDataCount,
            itemStyle: {
              color(params) {
                const { dataIndex } = params;
                let color = {
                  type: 'linear',
                  x: 1,
                  y: 0,
                  x2: 0,
                  y2: 0,
                  colorStops: [
                    {
                      offset: 0,
                      color: colors[dataIndex] ? colors[dataIndex][0] : 'red',
                    },
                    {
                      offset: 1,
                      color: colors[dataIndex] ? colors[dataIndex][1] : 'red',
                    },
                  ],
                };
                return color;
              },
            },
          },
        ],
      };
      myChart.setOption(option);
    },
    getProposedInvestments() {
      getProposedInvestments().then((res) => {
        const { status, data } = res;
        const { proposedInvestmentsWayDis } = JSON.parse(data);
        if (status === 200) {
          // this.investmentsWayData=[{0: "合资", 1: "合作", 2: "独资", 3: "其他"}]
          this.investmentsWayData = proposedInvestmentsWayDis.map((item) => {
            return item.wayDis;
          });
          // this.investmentsWayDataCount=[{0: "496", 1: "372", 2: "248", 3: "124"}]
          this.investmentsWayDataCount = proposedInvestmentsWayDis.map((item) => {
            return item.count;
          });
          // this.investmentsWayDataCounts=[{itemStyle:
    // color:{
    // 0: "rgba(240, 7, 100, 1)"
    // 1: "rgba(0, 215, 229, 1)"}
    // value: "496"}]
          this.investmentsWayDataCounts = proposedInvestmentsWayDis.map((item, index) => {
            return {
              value: item.count,
              itemStyle: {
                color: colors[index],
              },
            };
          });
          this.initMap();
        }
      });
    },
  },
};
</script>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持极客世界。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
webpack -v报错解决方案发布时间:2022-02-05
下一篇:
vue axios拦截器常用之重复请求取消发布时间:2022-02-05
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap