echarts的图例,自定义格式化显示的数据如何右对齐

如图

clipboard.png

右边的数据是我自定义格式化显示出来的,代码如下

legend: {
            show: 'true',
            top: '30%',
            left: '50%',
            orient: 'vertical',
            icon:"circle",
            itemWidth:8,
            itemHeight:8,
            data:this.currentLegend,
            selectedMode: false,
            // 自定义格式化数据
            formatter: name => {
              var index = 0;
              var clientlabels = this.currentLegend;
              var clientcounts = this.currentData;
              clientlabels.forEach(function(value, i) {
                if (value == name) {
                  index = i;
                }
              });
              return name + " " + clientcounts[index].value + '%'
            }
        },

但是我想要实现下面的效果,不知道如何实现

clipboard.png

阅读 14k
5 个回答

https://blog.csdn.net/GXing00...
可以看看这篇博客

let arr = [  '{a|' + name + '}{b|' + target + '}{c|' + ((target / total) * 100).toFixed(2) + '%];
 
                          return arr.join('\n')
textStyle: {
                          rich: {
                              a: {
                                  verticalAlign: 'right',
                                  fontSize: 12,
                                  align: 'left',
                                  // padding:[0,28,0,0],
                                  width: 70
                              },
                              b: {
                                  fontSize: 12,
                                  align: 'left',
                                  // padding:[0,28,0,0],
                                  width: 50
 
                              },
                              c: {
                                  fontSize: 12,
                                  align: 'left',
                                  width: 50
                              }
                          }
                      },
                  },
formatter: name => {
            let space = `\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000`
            space = space.slice(0, 7 - name.length)
            return `${name}${space}${this.objData[name]}`
          }

可以试试这样

富文本标签 https://echarts.baidu.com/opt...

legend: {
            show: 'true',
            top: '30%',
            left: '50%',
            orient: 'vertical',
            icon:"circle",
            itemWidth:8,
            itemHeight:8,
            data:this.currentLegend,
            selectedMode: false,
            // 自定义格式化数据
            formatter: name => {
              var index = 0;
              var clientlabels = this.currentLegend;
              var clientcounts = this.currentData;
              clientlabels.forEach(function(value, i) {
                if (value == name) {
                  index = i;
                }
              });
              return `{name|${name}}  {value|${clientcounts[index].value}%}`
            },
            textStyle: {
              rich: {
                name: {
                  width: 80
                },
                value: {
                  width: 80,
                  align: 'right'
                }
              }
            }
        },
relVal += '<br/><b>' + params[i].marker + params[i].seriesName + '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + '<span style="float: right">' + (100 *
                parseFloat(params[i].value) / parseFloat(total)).toFixed(2) + '%' + '</span>'

使用 float: right 即可

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题