Echart柱状图x轴label显示文本与图片

柱状图x轴label显示图片效果如下:
在这里插入图片描述

配置信息
在这里插入图片描述

import EchartInit from '@/components/EchartInit';

const IMG = [
  'https://scpic.chinaz.net/Files/pic/icons128/8328/h1.png',
  'https://scpic.chinaz.net/Files/pic/icons128/8319/w2.png',
  'https://img0.baidu.com/it/u=3119542616,1165410720&fm=26&fmt=auto',
  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F061H0102U6%2F20061G02U6-12-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644314407&t=aa49089b06c80ff5c9e3404d3ec85382',
  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F21042G339292K3-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644314407&t=e3a817c74754fdade94aa51858689928',
  'https://scpic.chinaz.net/Files/pic/icons128/8308/d5.png',
  'https://scpic.chinaz.net/Files/pic/icons128/8304/e7.png'
]
export default function BarEchart(props: any) {

  const options = {
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      axisLabel: {
        formatter: (value) => {
         return value + '\n'+'{' + value + '| }';
        },
        rich: {
          Mon: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[0]
            }
          },
          Tue: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[1]
            }
          },
          Wed: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[2],
            },
          },
          Thu: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[3],
            },
          },
          Fri: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[4],
            },
          },
          Sat: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[5],
            },
          },
          Sun: {
            height: 40,
            width: 40,
            backgroundColor: {
              image: IMG[6],
            },
          }
        }
      }
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [120, 200, 150, 80, 70, 110, 130],
        type: 'bar',
        showBackground: true,
        backgroundStyle: {
          color: 'rgba(180, 180, 180, 0.2)'
        }
      }
    ]
  };

  return (
    <div style={{height :300, width:'100%'}}>
      <EchartInit options={options} />
    </div>
  )
}
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值