【发布时间】:2016-07-20 07:10:22
【问题描述】:
这是您在 amCharts 中定义标题的方式:
"titles": [{
"text": "My Chart Title"
}, {
"text": "My Chart Title 222",
"bold": false
}]
但是我不能定义字体系列(如 Arial),因为 Title 类不支持这一点。知道如何实现吗?
【问题讨论】:
标签: amcharts
这是您在 amCharts 中定义标题的方式:
"titles": [{
"text": "My Chart Title"
}, {
"text": "My Chart Title 222",
"bold": false
}]
但是我不能定义字体系列(如 Arial),因为 Title 类不支持这一点。知道如何实现吗?
【问题讨论】:
标签: amcharts
首先需要确定正确的标题。
为此,您需要在配置中添加 addClassNames。
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"addClassNames": true,
"theme": "none"
});
接下来,您必须为您的标题设置一个id。 AmCharts 将在 DOM-Element 上创建一个附加类,其中包括指定的 id。
"titles": [{
"text": "My Chart Title",
"id": "main"
}]
结果类: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}
附言classNamePrefix 默认:'amcharts-'
【讨论】: