Search code examples
amcharts

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?


Solution

  • 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.