echarts给x轴添加rich各种图标

1. 选择合适的rich图标

      const weatherIcons = {
        Sunny: 'https://echarts.apache.org/examples/data/asset/img/weather/sunny_128.png',
        Showers: 'https://echarts.apache.org/examples/data/asset/img/weather/showers_128.png'
      }

2. 设置X轴

提示: 添加rich属性,通过 formatter 函数自定义渲染

          xAxis: [
            {
              type: 'category',
              axisTick: {
                show: false
              },
              axisLine: {
                show: true,
                lineStyle: {
                  type: '',
                  color: '#000'
                }
              },
              axisLabel: {
                formatter: function (value, index) {
                // 根据业务场景判断显示哪种图标
                  if(isRain[index] === '1'){
                   // 图标显示
                    return "{Showers|}"+value
                  }else {
                  // 图标显示
                    return "{Sunny|}"+value
                  }
                },
                // inside: false,
                // textStyle: {
                //   color: '#000', // x轴颜色
                //   fontWeight: 'normal',
                //   fontSize: '14',
                //   lineHeight: 22
                // },
                rich: {
                  value: {
                    lineHeight: 20,
                    align: 'center'
                  },
                  Sunny: {
                    height: 20,
                    align: 'center',
                    backgroundColor: {
                      image: weatherIcons.Sunny
                    }
                  },
                  Showers: {
                    height: 20,
                    align: 'center',
                    backgroundColor: {
                      image: weatherIcons.Showers
                    }
                  }
                }
              },
 //  x轴展示的数据
              data: xAxisData
            }
          ],
ECharts是一款基于JavaScript的可视化图表库,可以用于构建各种类型的图表,如折线图、柱状图、饼图等。EChartsRich Text组件提供了强大的富文本功能,可以在图表中添加图片、文本、链接等元素,增强图表的可视化效果。下面是一些echarts rich用法的示例: 1. 在图表中添加图片: ```javascript rich: { logo: { // 这里可以设置图片的路径和大小 backgroundColor: { image: 'https://echarts.apache.org/zh/images/favicon.png' }, height: 30 } }, series: [{ type: 'pie', data: [ {value: 335, name: '直接访问'}, {value: 310, name: '邮件营销'}, {value: 234, name: '联盟广告'}, {value: 135, name: '视频广告'}, {value: 1548, name: '搜索引擎'} ], label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } }, // 在这里引用rich配置项中的图片 graphic: { elements: [{ type: 'image', style: { image: 'logo', width: 30, height: 30 }, left: 'center', top: 'center' }] } }] ``` 2. 在图表中添加文本: ```javascript rich: { a: { fontSize: 20, fontWeight: 'bold', color: '#333', lineHeight: 30 } }, series: [{ type: 'pie', data: [ {value: 335, name: '直接访问'}, {value: 310, name: '邮件营销'}, {value: 234, name: '联盟广告'}, {value: 135, name: '视频广告'}, {value: 1548, name: '搜索引擎'} ], labelLine: { show: false }, label: { show: false }, // 在这里引用rich配置项中的文本 graphic: [{ type:'text', left:'center', top:'center', style:{ text:'总计', rich:{ a:{ fontSize:20, fontWeight:'bold', color:'#333', lineHeight:30 } } } }] }] ``` 3. 在图表中添加链接: ```javascript rich:{ a:{ color:'#fff', backgroundColor:'#108ee9', padding:[5,10], borderRadius:5, fontSize:'18', lineHeight:'30' } }, series:[{ type:'pie', data:[ {value:400, name:'Apple'}, {value:335, name:'Samsung'}, {value:300, name:'Huawei'}, {value:200, name:'Xiaomi'}, {value:100, name:'Oppo'} ], labelLine:{ show:false }, label:{ show:false }, // 在这里引用rich配置项中的链接 graphic:[{ type:'group', left:'center', bottom:'10%', children:[{ type:'text', zlevel:100, left:'center', style:{ text:'More Info', font-size:'18px', fontWeight:'bold' }, action:{ type:'redirect', link:'https://www.example.com/' } },{ type:'rect', zlevel:-1, left:'center', top:'middle', shape:{ width:'100%', height:'100%' }, style:{ fill:'#fff', opacity:.01 }, action:{ type:'redirect', link:'https://www.example.com/' } }] }] }] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值