echart写横向柱状图及颜色自定义

效果图

<div class="musicalInstrument">
    <div class="divHeader">{{ musicalInstrument.name }}</div>
    <div class="cutLine"></div>
    <div class="divComponent">
      <div class="instrument">
        <div id="myBarChart" :style="{ width: '100%', height: '100%' }"></div>
      </div>
    </div>
  </div>
export default {
  computed: {},
  watch: {},
  data() {
    return {
      musicalInstrument: {
        name: "乐器喜爱度排行",
        option: {
          title: {},
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow",
            },
          },
          legend: {
            data: [],
          },
          grid: {
            left: "20%",
            top: "4%",
            width: "76%",
            height: "75%",
          },
          xAxis: {
            type: "value",
            splitLine: {
              lineStyle: {
                color: "#7b7575",
                type: "dashed",
              },
            },
            axisLine: {
              lineStyle: {
                color: "black",
              },
            },
            axisTick: {
              show: false,
            },
          },
          yAxis: {
            type: "category",
            data: ["吉他", "钢琴", "小提琴", "架子鼓", "钢琴", "唢呐"],
            axisLine: {
              lineStyle: {
                //设置y轴字体颜色
                color: "black",
              },
            },
            axisTick: {
              show: false,
            },
          },
          series: [
            {
              name: "",
              type: "bar",
              barWidth: "30%", //设置柱子宽度
              data: [10, 9, 12, 13, 13, 13],
              itemStyle: {
                normal: {
                  //设置柱状图颜色,注意:如果颜色太少的话,后面颜色不会自动循环
                  color: function (params) {
                    var colorList = [
                      "blue",
                      "blue",
                      "orange",
                      "orange",
                      "green",
                      "green",
                    ];
                    return colorList[params.dataIndex];
                  },
                },
              },
            },
          ],
        },
      },
    };
  },
  mounted() {
    this.myBarChart = this.$echarts.init(document.getElementById("myBarChart"));
    this.myBarChart.setOption(this.musicalInstrument.option);
  },
};
* {
  margin: 0;
  padding: 0;
}

.musicalInstrument {
  border-radius: 16px;
  height: 32%;
  width: 100%;
  background: rgb(236, 235, 235);
}

.divHeader {
  font-size: 15px;
  padding: 10px 15px;
  font-weight: bold;
}

.cutLine {
  width: 100%;
  height: 5px;
  background-image: linear-gradient(to right, #0a3e55, #8f9192);
}

.divComponent {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 99%;
  height: calc(100% - 45px);
  padding: 10px 15px;
}
.instrument {
  width: 100%;
  height: 100%;
}

/*滚动条相关css设置*/
::-webkit-scrollbar {
  width: 0px; /*滚动条宽度*/
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值