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 {
      maxStr: 400,
      yInterval: 80,
      myData: [122, 45, 67, 78, 46],
      averageData: [32, 34, 6, 73, 84, 40]
    }
  },
  //外部传入数据的话要监听数据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.myData, this.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,
          containLable: true
        },
        tooltip: {},
        xAxis: {
          data: ["看过我的", "沟通过的", "收到简历", "曝光人数"],
          axisLine: {
            lineStyle: {
              type: 'solid',
              color: '#eeeeee', //x左边线的颜色
              fontSize: 13,
              width: '0.5' //坐标线的宽度
            }
          },
          axisLabel: { //x轴字体
            textStyle: {
              color: '#333333',
              fontSize: 13
            }
          },
        },
        yAxis: {
          type: 'value',
          min: 0,
          max: this.maxStr,
          interval: this.yInterval,
          axisLine: {
            lineStyle: {
              type: 'solid',
              color: '#fff', //左边线的颜色
              width: '0.5' //坐标线的宽度
            }
          },
          axisLabel: {
            textStyle: {
              color: '#333333',
              fontSize: 13
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: ['#eeeeee'],
              width: 1,
              type: 'solid'
            }
          }

        },
        legend: {
          itemWidth: 11,
          itemHeight: 12,
          symbolKeepAspect: true,
          textStyle: {
            fontSize: 11,
            lineHeight: 0,
            backgroundColor: "rgba(11, 164, 19, 1)"
          },
          // icon: `image://${averageIcon}`,

          data: [
            {
              name: '我的',
              // icon: `image://${myIcon}`//自定义小图标
            },
            {
              name: '行业平均',
              // icon: `image://${averageIcon}`
            }
          ],
          align: 'left',
          right: 40,
          top: '0',
          textStyle: {
            fontSize: 12,
            textAlign: 'center',
            color: '#333333',
            magrinRight: 3
          },
        },
        series: [{
          name: '我的',
          type: 'bar',
          data: myData,
          barWidth: 16, //柱子宽度
          barGap: '50%',//间距
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#4695F3'
            },
            formatter: function (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: '#A5CCF6'
              }, {
                offset: 1,
                color: '#4695F3'
              }]),
              barBorderRadius: [4, 4, 0, 0],
            }
          }
        },
        {
          name: '行业平均',
          type: 'bar',
          data: averageData,
          barWidth: 16,
          barGap: '50%',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#FE8401'
            },
            formatter: function (params) {
              return params.value
            }
          },
          itemStyle: {
            normal: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                offset: 0,
                color: '#FFB235'
              }, {
                offset: 1,
                color: '#FE8401'
              }]),
              barBorderRadius: [4, 4, 0, 0],
            },
            emphasis: {
              barBorderRadius: 30
            },
          }
        }
        ]
      }, true);
    },

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

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

  }
}
</script>
 
<style scoped>
.echarts_con {
  width: 100%;
  margin: 0 auto;
  margin-top: 8px;
  border-radius: 20px;
  background: #fff;
  padding-bottom: 35px;
}
.echarts_main {
  width: 100%;
  margin: 0 auto;
  padding-top: 20px;
  margin-bottom: -32px;
  margin-right: 20px;
  margin-left: 20px;
}
.bottom {
  width: 90%;
  margin: 0 auto;
  background: #fef8e1;
  border-radius: 6px;
  height: 100%;
  margin-top: 16px;
}
.bottom_con {
  width: 90%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 34px;
  line-height: 34px;
}
.bottom_text {
  height: 34px;
  line-height: 34px;
  font-size: 13px;
  font-family: PingFang, PingFang-SC;
  font-weight: SC;
  text-align: left;
  color: #fa5d1d;
}
.right_close {
  width: 13px;
  height: 13px;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue是一种流行的JavaScript框架,用于构建用户界面。ECharts是一种用于创建交互性和可视化图的图库。在生产环境中,可以使用VueECharts来创建一个生产任务看板。 首先,我们可以使用Vue框架来构建用户界面。通过Vue的组件化架构,我们可以将任务看板拆分为多个可重用的组件,例如任务列、进度条、功能按钮等。这样可以使代码更可维护和可扩展。同时,Vue提供了响应式的数据绑定机制,可以实时更新任务看板的数据,并与后端进行数据交互。 然后,我们可以使用ECharts库来创建可视化图,以展示任务看板上的数据。例如,可以使用饼图来显示任务的进度分布,柱状图来展示各个任务的完成情况,折线图来展示任务的趋势等。ECharts提供了丰富的图类型和交互功能,可以根据实际需求进行灵活配置。 在整个过程中,我们可以利用Vue的生命周期钩子函数来实现数据的获取、更新和渲染。当用户发起操作时,可以通过Vue的事件机制来触发相应的业务逻辑。例如,当用户点击任务列中的某个任务时,可以发送请求获取该任务的详细信息,并在界面上展示出来。 最后,为了提高用户体验,我们可以将任务看板进行排版和样式的优化,使其在不同设备和浏览器上都能良好展示。同时,可以增加一些交互功能,例如拖拽任务、快速搜索任务等,以提高用户的生产效率。 总结而言,通过使用VueECharts,我们可以实现一个功能齐全、交互性强的生产任务看板。它可以直观展示任务的状态和进度,并提供方便的操作和管理功能,帮助用户更好地进行生产任务的监控和调度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值