amCharts:如何在图表标题中设置字体系列?

amCharts: How to set font family in chart title?

这就是您在 amCharts 中定义标题的方式:

"titles": [{
    "text": "My Chart Title"
}, {
    "text": "My Chart Title  222",
    "bold": false
}]

但是我无法定义字体系列(如 Arial),因为标题 class 不支持此功能。知道如何实现吗?

首先需要确定正确的标题。
为此,您需要在配置中添加 addClassNames

var chart = AmCharts.makeChart("chartdiv", {
    "type": "serial",
    "addClassNames": true,
    "theme": "none"
});

接下来您必须为标题设置 idAmCharts 将在包含指定 id.

DOM-Element 上创建一个额外的 class
"titles": [{
        "text": "My Chart Title",
        "id": "main"
 }]

结果 class:amcharts-title-main

现在您要做的就是在使用 jQuery:

绘制图表时更改字体系列
$(".amcharts-title-main").css("font-family", "Arial");

工作demo

评论补充:@gerric 要在 4 版本中添加 类,您需要:

import * as am4core from '@amcharts/amcharts4/core'
...
am4core.options.autoSetClassName = true

https://www.amcharts.com/docs/v4/reference/options/ https://www.amcharts.com/docs/v4/tutorials/chart-element-class-names-and-css/

将生成标题,类 模板:${classNamePrefix}${id} P.S。默认的类名前缀:'amcharts-'