You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Charts v43使用NumberFormat设置百分比格式时报Too many percent/permill错误

问题根因

该报错是Google Charts v43版本的已知缺陷,版本内置的ICU数字格式解析逻辑存在问题,当自定义pattern的正负子模式中同时包含%符号时,就会触发Too many percent/permill异常。

解决方法

你不需要手动拼接百分号,直接用NumberFormat自带的原生参数配置即可实现需求,无需自定义带%的pattern,也不用自行处理数值转换:

new google.visualization.NumberFormat({
  negativeColor: 'black',
  percent: true, // 组件自动将原始数值乘以100后追加%后缀
  decimalDigits: 1, // 保留1位小数,匹配你需要的.0精度
  negativeParens: true // 负数用括号包裹,和你预期的负数格式一致
})

上述配置最终的渲染效果和你最初写的#,##0.0%;(#,##0.0%)pattern完全一致,同时可以规避v43版本的格式解析bug。

如果你确实需要自定义pattern写法,只需要去掉负号子模式中的重复%即可,ICU格式规范下第一个子模式的符号后缀会自动继承到负号子模式,调整后如下:

new google.visualization.NumberFormat({
  negativeColor: 'black',
  pattern: "#,##0.0%;(#,##0.0)"
})

内容的提问来源于stack exchange,提问作者gwoody1984

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 00:45:03