ps0604
ps0604

Reputation: 1071

amCharts: How to set font family in chart title?

This is how you define a title in amCharts:

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

However I cannot define font family (as Arial) as the Title class does not support this. Any idea how this can be achieved?

Upvotes: 3

Views: 7958

Answers (2)

Supplement to the comment: @gerric For add classes in 4 version you need:

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/

For titles will be generated, classes by template: ${classNamePrefix}${id} P.S. classNamePrefix by default: 'amcharts-'

Upvotes: 1

gerric
gerric

Reputation: 2297

First it is necessary to identify the right title.
For that you need to add addClassNames in your configuration.

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

Next you have to set an id for your title. AmCharts will create an additional class on the DOM-Element thats includes the specified id.

"titles": [{
        "text": "My Chart Title",
        "id": "main"
 }]

resulting class: amcharts-title-main

Now everything you have to do is changing the font family whenever the chart is drawn using jQuery:

$(".amcharts-title-main").css("font-family", "Arial");

Working demo.

Upvotes: 2

Related Questions