如何修改AG Grid条形图的标签fontSize?
AG Grid条形图轴标签字体大小不生效的解决方法
你的问题出在主题配置的层级和轴类型匹配上:你参考的是数值轴的配置,但你的水平条形图中,显示年份的是类别轴,同时overrides里的全局轴配置没有精准对应轴类型,导致样式未被正确应用。
修正后的配置方案
直接在theme.overrides中针对类别轴和数值轴分别设置标签字体大小,覆盖全局默认样式:
{ theme: { palette: { fills: ["red", "blue"], strokes: ["#000"], }, overrides: { common: { title: { enabled: true, fontSize: 14, fontWeight: 600, textAlign: "left", fontFamily: "Segoe UI", spacing: 24, text: "qwe", }, padding: { left: 16, top: 16, right: 16, bottom: 0, }, }, // 针对显示年份的类别轴设置标签样式 categoryAxis: { label: { fontSize: 40, }, }, // 针对显示数值的数值轴设置标签样式 numberAxis: { label: { fontSize: 30, }, }, }, }, data: [ { quarter: "1987", iphone: 96, mac: 22, }, { quarter: "1990", iphone: 104, mac: 22, }, ], series: [ { type: "bar", xKey: "quarter", yKey: "iphone", stacked: true, direction: "horizontal", }, { type: "bar", xKey: "quarter", yKey: "mac", stacked: true, direction: "horizontal", }, ], };
关键说明
- 水平条形图中,
xKey绑定字符串类型数据时,对应的是类别轴,而非你参考的数值轴; theme.overrides中直接指定轴类型的配置优先级高于全局axes配置,能确保样式精准应用到目标轴;- 移除了原配置中冲突的全局轴配置,避免样式层级混乱。
内容的提问来源于stack exchange,提问作者Sergey
相关产品推荐
相关产品推荐

