[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`

オープン 初心者向け
#21,843 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@0z5a がすでに取り組んでいます。

2026年11月15日 から。

  • #21844 @0z5a による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

src/util/format.ts から始めてください。formatTpl は {a} を {a0} に書き換えてから、tpl.replace(wrapVar(alias), ...) で値を置換しますが、文字列パターンの replace は最初の一致だけに作用します。formatTplSimple にも同じ欠陥があります。両方を、挿入値がリテラルのまま保たれて $ の扱いが引き続き成り立つ replace-all に置き換え、次に jest の単体テストで繰り返しの {b}/{c}、繰り返しのインデックス付き変数、formatTplSimple をカバーし、シリーズラベルのフォーマッタが Mon: 120 | Mon: 120 をレンダリングすることを確認してください。報告者はテスト付きのパッチがすでに存在すると述べているので、重複させる前にメンテナーに確認してください。

索引モデルが issue の本文から書いたものです。

説明

en pending
Version

6.1.0 (also reproduced on current master 34f4d92 and release 8ca03d4)

Link to Minimal Reproduction

https://echarts.apache.org/examples/en/editor.html?code=b3B0aW9uID0gewogICAgeEF4aXM6IHsgdHlwZTogJ2NhdGVnb3J5JywgZGF0YTogWydNb24nLCAnVHVlJ10gfSwKICAgIHlBeGlzOiB7fSwKICAgIHNlcmllczogW3sKICAgICAgICB0eXBlOiAnYmFyJywKICAgICAgICBuYW1lOiAnU2FsZXMnLAogICAgICAgIGRhdGE6IFsxMjAsIDIwMF0sCiAgICAgICAgbGFiZWw6IHsgc2hvdzogdHJ1ZSwgZm9ybWF0dGVyOiAne2J9OiB7Y30gfCB7Yn06IHtjfScgfQogICAgfV0KfTsK&enc=base64

Steps to Reproduce
  1. Create a chart with this option:
option = {
    xAxis: { type: 'category', data: ['Mon', 'Tue'] },
    yAxis: {},
    series: [{
        type: 'bar',
        name: 'Sales',
        data: [120, 200],
        label: { show: true, formatter: '{b}: {c} | {b}: {c}' }
    }]
};
  1. Look at the bar labels.

The same thing happens with the public helper:

echarts.format.formatTpl('{b}: {c} | {b}: {c}', {
    $vars: ['seriesName', 'name', 'value'], seriesName: 'Sales', name: 'Mon', value: 120
});
// 6.1.0 returns "Mon: 120 | {b}: {c}"

Rendered label text for three formatters, read back from the chart in the repo's jest unit-test setup. The first and third are controls (each variable used once, and a repeated {@[0]}):

"{b}: {c}"                           -> ["Mon: 120","Tue: 200"]
"{b}: {c} | {b}: {c}"                -> ["Mon: 120 | {b}: {c}","Tue: 200 | {b}: {c}"]
"{@[0]} | {@[0]}"                    -> ["120 | 120","200 | 200"]
Current Behavior

Only the first occurrence of each template variable is substituted. Later occurrences of the same variable are shown literally, e.g. the label reads Mon: 120 | {b}: {c}. Indexed variables in multi-series templates behave the same way: '{a0}={c0}, {a1}={c1}; {a0}={c0}, {a1}={c1}' gives A=1, B=2; {a0}={c0}, {a1}={c1}.

Expected Behavior

Every occurrence of a variable is replaced: Mon: 120 | Mon: 120. The option manual for series label.formatter lists {a}, {b}, {c}, {@xxx} and {@[n]} as string template variables (and tooltip.formatter lists {a} to {e} plus {a0}, {a1}, ...), and it does not say a variable can only be used once. In the same formatter, {@xxx} dimension variables are already replaced at every occurrence, and so are the time tokens ({yyyy}, {MM}, ...) in time axis label templates.

Environment
- OS: macOS 26 (arm64)
- Browser: not browser specific (reproduced in Node.js 24 with dist/echarts.js 6.1.0, and in the repo's jest/jsdom unit tests)
- Framework: none
Any additional comments?

Root cause: formatTpl in src/util/format.ts calls tpl.replace(wrapVar(alias), ...) with a string pattern, both when it rewrites {a} to {a0} and when it inserts the values. String.prototype.replace with a string pattern replaces only the first match (ECMA-262). formatTplSimple, which is used for the calendar and matrix label formatters, has the same pattern. formatTpl is used for series label formatters, string tooltip.formatter templates and echarts.format.formatTpl.

Suggested fix: replace all occurrences in both functions, for example with a small str.split(search).join(value + '') helper. That keeps the inserted value literal, so the $ handling from #21751 still works. I have a patch with unit tests (repeated {b}/{c}, repeated indexed variables, formatTplSimple, a series label check) and can open a PR if that helps.

This issue was drafted with Claude Code (claude-opus-5-5); the results above are from the runs described.

主要言語
TypeScript
スター
67.7k
フォーク
19.9k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/echarts のほかの issue

apache/echarts の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。