apache / apache/echarts

[Feature] Add final tick number as third parameter to axis label formatter

Open
#19,794 4 comments 0 reactions 0 assignees View on GitHub
en new-feature pending
Dominant language
TypeScript
Stars
67.3k
Forks
19.8k
Avg merge
11d 14h
Merged PRs (30d)
8

Description

### What problem does this feature solve?

**Case**

Rather than show a numerical value of the last (upper bound) label on the Y Axis, it is sometimes desirable to show something else programmatically.

**Context**

We had a goal to show a unit of measure (ex: kWh, m/s, or A) on the last Y axis label. Since assigning axis.splitNumber doesn't always linearly corelate to the number of ticks, we couldn't determine the last tick without risky code.

**Rationale**

By having the final tick number in the axis label formatter, we could determine what tick was the last one and easily write that logic within the formatter. Without this, we could only entertain a solution [as described in Stack Overflow here](https://stackoverflow.com/a/77102205), which not intended to be done, and requires that the chart actually be rendered before we apply the actual formatting that we want.

### What does the proposed API look like?

**Current** ([described in docs](https://echarts.apache.org/en/option.html#xAxis.axisLabel.formatter))

```
formatter: function (value, index) {
return value + 'kg';
}
```

**Proposed**

```
formatter: function (value, index, totalTicks) {
const desiredLastTickLabel = "desired value here"
const isLastTick = index === totalTicks - 1

return isLastTick ? desiredLastTickLabel : value + 'kg';
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.