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

如何在AMCharts V5中为XY图表的ValueAxis添加坐标轴标题

AMCharts 5 XY图表为X/Y轴添加标题的实现方法

AMCharts 5 中为 ValueAxis(X轴、Y轴)添加标题的逻辑和 V4 不同,以下是具体实现方式:

方式一:初始化轴时直接配置标题

创建轴的时候,在配置参数里直接指定 title 字段:

// 创建Y轴
let yAxis = chart.yAxes.push(
  am5xy.ValueAxis.new(root, {
    title: "营业额(百万美元)",
    renderer: am5xy.AxisRendererY.new(root, {})
  })
);

// 创建ValueAxis类型的X轴
let xAxis = chart.xAxes.push(
  am5xy.ValueAxis.new(root, {
    title: "时间",
    renderer: am5xy.AxisRendererX.new(root, {})
  })
);

方式二:动态修改轴标题

如果需要后续调整标题内容,使用 set() 方法即可:

// 更新Y轴标题
yAxis.set("title", "更新后的营业额(百万美元)");

// 更新X轴标题
xAxis.set("title", "更新后的时间");

自定义标题样式

如果需要调整标题的字体、颜色、间距等样式,可以将 title 设置为配置对象:

yAxis.set("title", {
  text: "营业额(百万美元)",
  fontSize: 14,
  fill: "#333",
  paddingTop: 10,
  fontWeight: "bold"
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 23:30:48