[Bug] String formatter templates only replace the first occurrence of `{a}`/`{b}`/`{c}`
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 80/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- data-visualization
Línea de trabajo
Empieza en src/util/format.ts: formatTpl reescribe {a} como {a0} y luego sustituye valores con tpl.replace(wrapVar(alias), ...), y replace con patrón de cadena solo afecta a la primera coincidencia; formatTplSimple tiene el mismo defecto. Cambia ambos por un replace-all que mantenga literal el valor insertado para que el manejo de $ siga cumpliéndose, luego cubre {b}/{c} repetidos, variables indexadas repetidas y formatTplSimple en las pruebas unitarias de jest y comprueba que un formateador de etiquetas de serie renderice Mon: 120 | Mon: 120. Ten en cuenta que el reportero dice que ya existe un parche con pruebas, así que confírmalo con un maintainer antes de duplicarlo.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version
6.1.0 (also reproduced on current master 34f4d92 and release 8ca03d4)
Link to Minimal Reproduction
Steps to Reproduce
- 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}' }
}]
};
- 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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 67.7k
- Forks
- 19.9k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/echarts
-
[Bug] Inverse axis collapses the grid with outerBoundsContain when a tick is near the axis edgePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoen pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
[Bug] The zoom cursor in the toolbox area is incorrectPosiblemente ocupada @waterWang la tomó hace 98 días. Abiertobug en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
en pending
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de apache/echarts
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
pollen-robotics/reachy-mini-desktop-app#341 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
mike-north/AgentMonitors#648 ·
Los mantenedores suelen responder en 1 día
-
Position: a popup placed again from between two layout steps lands a fraction of a pixel offAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
vercel-labs/ui#700 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días