温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用vue和echart实现双柱状图

发布时间:2021-09-06 19:44:35 阅读:238 作者:chen 栏目:开发技术
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

本篇内容主要讲解“怎么用vue和echart实现双柱状图”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用vue和echart实现双柱状图”吧!

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

效果图:

怎么用vue和echart实现双柱状图

一、安装

版本号建议安装"echarts": "^4.8.0”,其它版本init会报错

1、 首先需要安装echarts依赖包

npm install --save echarts@4.8.0

2、 或者使用国内的淘宝镜像:

npm install -g cnpm --registry=https://registry.npm.taobao.org
<template>
  <div class="echarts_con">
    <div
      class="echarts_main"
      ref="dialog_root"
      title="节点指标"
      @close="hideData()"
    >
      <!--负载情况-->
      <div
        ref="bar_dv"
        :style="{
          width: '100%',
          minHeight: '300px',
        }"
      ></div>
    </div>
  </div>
</template>
 
<script>
import echarts from 'echarts'
// import myIcon from './image/hot_icon.png' //自定义图标
// import averageIcon from './image/hot_icon.png'
export default {
  name"Echarts",
  data () {
    return {
      maxStr400,
      yInterval80,
      myData: [12245677846],
      averageData: [32346738440]
    }
  },
  //外部传入数据的话要监听数据start
  // props: {
  //   myData: {
  //     type: Array,
  //     default: []
  //   },
  //   averageData: {
  //     type: Array,
  //     default: []
  //   }
  // },
  // computed: {
  //   address () {
  //     const { myData, averageData } = this
  //     return {
  //       myData,
  //       averageData
  //     }
  //   }
  // },
  // watch: {
  //   address: {
  //     handler: function (val) {
  //       this.compare(val.myData, val.averageData)
  //       let newArr = val.myData.concat(val.averageData)
  //       let maxNum = Math.max(...newArr)
  //       this.maxStr = maxNum
  //       if (maxNum >= 500) {
  //         this.yInterval = 200
  //       } else {
  //         this.yInterval = 50
  //       }
  //       this.drawLine(val.myData, val.averageData)
  //     },
  //     deep: true

  //   }
  // },
  // mounted () {
  // this.$nextTick(function () {
  //   this.drawLine();
  // });
  // },
  //外部传入数据的话要监听数据end

  mounted () {
    this.drawLine(this.myDatathis.averageData)
  },
  methods: {
    //判断一一对应数据低于平均就提示
    compare (arr1, arr2) {
      if (arr1[0] < arr2[0]) {
        this.isCompare = true
      } else if (arr1[1] < arr2[1]) {
        this.isCompare = true
      } else if (arr1[2] < arr2[2]) {
        this.isCompare = true
      } else if (arr1[3] < arr2[3]) {
        this.isCompare = true
      } else {
        this.isCompare = false
      }
    },
    clickClose () {
      this.isCompare = false
    },
    /*负载情况图标*/
    drawLine (a, b) {
      var myData = a;
      var averageData = b;
      let bar_dv = this.$refs.bar_dv;
      let myChart = echarts.init(bar_dv);
      var autoHeight = parseInt(this.maxStr / 100) * 10 + 100;
      myChart.getDom().style.height = autoHeight + "px";
      myChart.resize(); //自适应高度

      // 绘制图表
      myChart.setOption({
        title: { text'报表展示' },
        grid: {
          // left: 40,
          containLabletrue
        },
        tooltip: {},
        xAxis: {
          data: ["看过我的""沟通过的""收到简历""曝光人数"],
          axisLine: {
            lineStyle: {
              type'solid',
              color'#eeeeee'//x左边线的颜色
              fontSize13,
              width'0.5' //坐标线的宽度
            }
          },
          axisLabel: { //x轴字体
            textStyle: {
              color'#333333',
              fontSize13
            }
          },
        },
        yAxis: {
          type'value',
          min0,
          maxthis.maxStr,
          intervalthis.yInterval,
          axisLine: {
            lineStyle: {
              type'solid',
              color'#fff'//左边线的颜色
              width'0.5' //坐标线的宽度
            }
          },
          axisLabel: {
            textStyle: {
              color'#333333',
              fontSize13
            }
          },
          splitLine: {
            showtrue,
            lineStyle: {
              color: ['#eeeeee'],
              width1,
              type'solid'
            }
          }

        },
        legend: {
          itemWidth11,
          itemHeight12,
          symbolKeepAspecttrue,
          textStyle: {
            fontSize11,
            lineHeight0,
            backgroundColor"rgba(11, 164, 19, 1)"
          },
          // icon: `image://${averageIcon}`,

          data: [
            {
              name'我的',
              // icon: `image://${myIcon}`//自定义小图标
            },
            {
              name'行业平均',
              // icon: `image://${averageIcon}`
            }
          ],
          align'left',
          right40,
          top'0',
          textStyle: {
            fontSize12,
            textAlign'center',
            color'#333333',
            magrinRight3
          },
        },
        series: [{
          name'我的',
          type'bar',
          data: myData,
          barWidth16//柱子宽度
          barGap'50%',//间距
          label: {
            showtrue,
            position'top',
            textStyle: {
              color'#4695F3'
            },
            formatterfunction (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              colornew echarts.graphic.LinearGradient(0001, [{
                offset0,
                color'#A5CCF6'
              }, {
                offset1,
                color'#4695F3'
              }]),
              barBorderRadius: [4400],
            }
          }
        },
        {
          name'行业平均',
          type'bar',
          data: averageData,
          barWidth16,
          barGap'50%',
          label: {
            showtrue,
            position'top',
            textStyle: {
              color'#FE8401'
            },
            formatterfunction (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              colornew echarts.graphic.LinearGradient(0001, [{
                offset0,
                color'#FFB235'
              }, {
                offset1,
                color'#FE8401'
              }]),
              barBorderRadius: [4400],
            },
            emphasis: {
              barBorderRadius30
            },
          }
        }
        ]
      }, true);
    },

    hideData () {
      this.$emit("hideDialog")
    },

    confirm () {
      this.hideData();
    },

  }
}
</script>
 
<style scoped>
.echarts_con {
  width100%;
  margin0 auto;
  margin-top8px;
  border-radius20px;
  background#fff;
  padding-bottom35px;
}
.echarts_main {
  width100%;
  margin0 auto;
  padding-top20px;
  margin-bottom: -32px;
  margin-right20px;
  margin-left20px;
}
.bottom {
  width90%;
  margin0 auto;
  background#fef8e1;
  border-radius6px;
  height100%;
  margin-top16px;
}
.bottom_con {
  width90%;
  margin0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height34px;
  line-height34px;
}
.bottom_text {
  height34px;
  line-height34px;
  font-size13px;
  font-family: PingFang, PingFang-SC;
  font-weight: SC;
  text-align: left;
  color#fa5d1d;
}
.right_close {
  width13px;
  height13px;
}
</style>

到此,相信大家对“怎么用vue和echart实现双柱状图”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×