Skip to content

[Bug] axisLabel.formatter function (value, index) doesn't receive index numbers when using customValues #21216

Closed

Description

@mkf62

Version

6.0.0

Link to Minimal Reproduction

https://echarts.apache.org/examples/en/editor.html?code=MYewdgzgLgBAHgNQIYBsCuBTCMC8MDaAjAAzEA0MhAHAMwUBM1FNLFALAOxUC6A3AFChIsOABkkAIwwpseRKkwQAdAFskABwAUmuAEpcAPngwAVDACsugfxDqoAS3C4YAb34x4AQTj2IALld3DxgoAE91DACAcgA3BQwosiCPJB8IUXswSMDg4IgACxAAdwCoACdMJNyPcAAtDDKQb18ASTAAEww4AMJkmABfKuDU3wAVe2AAawC3apgC4tKKjCHc4DRoEBVkdCwA-V2IPsG-kfTJaRm-j3XN7fj_eB3FVeCAMxAytSgoBoC3tBgYAOJyaOIoCiZTp6HJzGBCCAgFAYJQoEAAc00AAM2tCYL4AgASFxQrr9LFWa7BMoYKBoMpgeDiKQyfCkuDcJRQEAAZXKmUxlLm_WOQROHlCzUes2CYQi0XBmCiYqGEAa9j2BD6Mty7SQUCQAXwVI8RFIFEIADZiNxXrkiOZyDB6GwbXbgkRaBa2OZbSaCPRzc6aGw_XCA0xnfQeO7TfRzPRmMRCGG4fgaEHCD7U3N06wozQc9V0z6LeYOEX7ZwqAwODaqZWQuFslEUJkEqKPNx-P1eEA

Steps to Reproduce

If using customValues for axisTick and axisLabel on xAxis of type: 'value', the axisLabel.formatter callback function doesn't receive index and instead only receives value. See demo which has a console.log statement called in the formatter function to see the value of the index (nothing will actually load on the chart due to the error it encounters in the formatter, but if you comment out formatter the chart will load fine).

Current Behavior

index is undefined.

Expected Behavior

index has a value based on the array used for customValues.

Environment

- OS: MacOS Sequoia v15.6
- Browser: Chrome v139.0.7258.128
- Framework: React 18.2

Any additional comments?

The simple workaround (at least in my demo) is to just do

const xValues = [100, 183, 218, 333, 478];
const xLabels = xValues.map((x) => x * 5);

axisLabel: {
      customValues: xValues,
      formatter: function (value) {
        const idx = xValues.indexOf(value)
        return xLabels[idx].toString();
      }
}

but that defeats the purpose of the formatter callback that's supposed to receive the indexes.

Activity

  1. added
    enThis issue is in English
    pendingWe are not sure about whether this is a bug/new feature.
    on Aug 22, 2025
  2. szymonpachucki commented on Aug 24, 2025

    @szymonpachucki

    Looking into it

  3. added and removed
    pendingWe are not sure about whether this is a bug/new feature.
    on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions