echarts 象形柱图

实现效果

在这里插入图片描述

实现思路

和常规柱图类似,配置项type: "bar" ,只有图片路径需要注意下。

实现代码
customBarCharts() {
      this.$api.dataDeck.manStructure().then(res => {
        var customBar = this.$echarts.init(
          document.getElementById("customBar")
        );
        var img2 = {
          a: "../../../static/girl.png",  //要写静态路径,否则会拿不到图片
          b: "../../../static/lightG.png"
        };

        var img1 = {
          a: "../../../static/boy.png",
          b: "../../../static/lightM.png"
        };

        var value = 1; // >0
        var option = {
          title: {
            text: "",
            subtext: "",
            textStyle: {
              color: "#000",
              fontSize: 16
            },
            left: "5%",
            top: "5%"
          },
          backgroundColor: "#fff",
          grid: {
            left: "10%",
            top: "5%",
            bottom: "10%",
            right: "10%",
            containLabel: true
          },
          tooltip: {
            trigger: "item"
          },
          xAxis: {
            splitLine: {
              show: false
            },
            axisLine: {
              show: false
            },
            axisLabel: {
              show: false
            },
            axisTick: {
              show: false
            }
          },
          yAxis: [
            {
              type: "category",
              inverse: false,
              data: [
                "男  " + (res.data.malePercent * 100).toFixed(2) + "%",
                "女  " + (res.data.femalePercent * 100).toFixed(2) + "%"
              ],
              axisLine: {
                show: false
              },
              axisTick: {
                show: false
              },
              splitLine: {
                show: false,
                lineStyle: {
                  type: "dotted",
                  color: "#000"
                }
              },
              axisLabel: {
                margin: 20,
                textStyle: {
                  color: "#000",
                  fontSize: 14
                }
              }
            }
          ],
          series: [
            {
              tooltip: {
                show: false
              },
              z: 2,
              type: "pictorialBar",
              symbolSize: ["10", "14"],
              symbolRepeat: "fixed",
              data: [
                {
                  value: value,
                  symbol: "image://" + img1.b  //图片前要加’image://‘,否则也不会显示图片
                },
                {
                  value: value,
                  symbol: "image://" + img2.b
                }
              ]
            },
            {
              z: 3,
              type: "pictorialBar",
              symbolSize: ["10", "14"], //上下图大小
              animation: true,
              symbolRepeat: "fixed",
              symbolClip: true,
              symbolPosition: "start",
              symbolOffset: [0, 0],
              data: [
                {
                  value: res.data.maleCount,
                  symbol: "image://" + img1.a
                },
                {
                  value: res.data.femaleCount,
                  symbol: "image://" + img2.a
                }
              ],
              label: {
                normal: {
                  show: true,
                  textStyle: {
                    color: "#000",
                    fontSize: 14
                  },
                  position: "right",
                  offset: [6, 0]
                }
              }
            },
            {
              type: "bar"
            }
          ]
        };
        customBar.setOption(option);
      });
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值