Echarts-横向柱状图实现

                                                                                                      

  • label,bar的颜色设置
  • y轴label文字样式设置
    • 文字居左展示
    • 前缀序号,圆圈样式

let colors = {
    1: "rgba(216,70,10,1)",
    2: "rgba(216,121,10,1)",
    3: "rgba(226,187,32,1)",
    4: "rgba(2,189,229,1)",
}
option = {
    title: {
        text: '世界人口总量'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        left: '-7%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        axisLabel: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLine: {
            show: false,
        },
    },
    yAxis: {
        type: 'category',
        inverse: true,
        axisTick: {
            show: false
        },
        axisLine: {
            show: false,
        },
        axisLabel: {
            margin: 120,
            textStyle: {
              align: 'left',
              color: (value, index) => {
                let sequence = index + 1;
                return sequence < 4 ? colors[sequence] : colors[4];
              },
            },
            formatter: (value, index) => {
              let sequence = index + 1;
              if (sequence == 1) {
                return "{one|1} {a|" + value + "}";
              } else if (sequence == 2) {
                return "{two|2} {b|" + value + "}";
              } else if (sequence == 3) {
                return "{three|3} {c|" + value + "}";
              }
              return "{default|} {d|" + value + "}";
            },
            rich: {
              a: {
                color: "rgba(216,70,10,1)",
              },
              b: {
                color: "rgba(216,121,10,1)",
              },
              c: {
                color: "rgba(226,187,32,1)",
              },
              d: {
                color: "white",
              },
              one: {
                backgroundColor: "rgba(216,70,10,1)",
                width: 20,
                height: 20,
                align: "center",
                color: "white",
                borderRadius: 10,
              },
              two: {
                backgroundColor: "rgba(216,121,10,1)",
                width: 18,
                height: 18,
                color: "white",
                align: "center",
                borderRadius: 9,
              },
              three: {
                backgroundColor: "rgba(226,187,32,1)",
                width: 16,
                height: 16,
                color: "white",
                align: "center",
                borderRadius: 8,
              },
              default: {
                backgroundColor: "white",
                width: 10,
                height: 10,
                borderRadius: 5,
              },
            },
          },
        data: ['世界人口(万)', '中国', '印度', '美国', '印尼', '巴西']
    },
    series: [
        {
            name: '2012年',
            type: 'bar',
            label: {
              show: true,
              position: 'right',
              textStyle: {
                color: "red",
                fontSize: 18,
              },
            },
            showBackground: true,
            backgroundStyle: {
              color: "rgba(1,38,74,0.4)"
            },
            data: [681807, 134141, 121594, 31000, 23438, 19325],
            itemStyle: {
              normal: {
                color: (serie) => {
                  let sequence = serie.dataIndex + 1;
                  return sequence < 4 ? colors[sequence] : colors[4];
                },
              },
            }
        }
    ]
};

拷贝到Echarts示例当中查看即可;

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值