apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.48k stars 19.62k forks source link

how to change the Y axisLabel to base-10 exponential form ? #15858

Closed ShawYuan97 closed 3 years ago

ShawYuan97 commented 3 years ago

What problem does this feature solve?

fig like this y axis Label

What does the proposed API look like?

axisLabel

echarts-bot[bot] commented 3 years ago

Hi! We've received your issue and please be patient to get responded. 🎉 The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe to our mailing list.

Have a nice day! 🍵

ShawYuan97 commented 3 years ago

fig

plainheart commented 3 years ago

参见以下两种方式

// 使用预设字符
const superscripts = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹'];
function toSuperscript(val) {
  return (val + '')
    .split('')
    .map(t => superscripts[t])
    .join('');
}

// 使用 Unicode
const superscriptUnicodes = ['B9', 'B2', 'B3'];
function toSuperscript2(val) {
  return (val + '')
    .split('')
    .map(t => String.fromCharCode('0x' + (t > 0 && t < 4 ? superscriptUnicodes[t - 1] : '207' + t)))
    .join('');
}

然后 ECharts 添加 axisLabel 配置

axisLabel: {
    formatter: (val) => {
      // 2 为底数 val 为指数
     // toSuperscript 或 toSuperscript2 均可
      return 2 + toSuperscript(val);
    }
}

相似问题:#13363 #7062