AmCharts v4 AmMap change language

心已入冬 提交于 2019-12-11 06:21:30

问题


I would like to change the language of a ammap (V4).

Therefore I followed the example which is provided here (but it is for V3): http://jsfiddle.net/tDqs2/25/

Here first the language get loaded via a script tag.

<script src="http://cdn.amcharts.com/lib/3/lang-maps/de.js">

Now if I follow the instructions I don't see any map. Here is my codepen: https://codepen.io/ms92o/pen/mjMpZy

that line does not work:

chart.language = 'de';

Looking at the API for language I do find a language property: https://www.amcharts.com/docs/v4/reference/mapchart/

But how do I set the language? The language constructor does not need any parameters

let language = new am4core.Language();
// How to change that language to 'DE'.

回答1:


A German translation was added earlier this month.

You can find other currently available translations here: https://github.com/amcharts/amcharts4-lang/tree/master/src

To change the language to say, German, we have to include the translation first as it isn't one of the bundled locales:

<script src="https://www.amcharts.com/lib/4/lang/de_DE.js"></script>

Then to change the language, each chart has a language property, we update its locale property, i.e. chart.language.locale, to the translation of choice:

chart.language.locale = am4lang_de_DE;

(Please note, updating the chart's language dynamically is not yet supported in v4. If it's something you're interested in, please subscribe to this GitHub issue to keep posted.)

Here's a simple chart demo in English: https://codepen.io/team/amcharts/pen/ZRaWJQ

Same demo in German via above code: https://codepen.io/team/amcharts/pen/4d968a6f292fca2dc59d5e75b0389e0e/

If you would like to roll your own translation or contribute to an existing one, check out the Creating Translations guide.



来源:https://stackoverflow.com/questions/51538057/amcharts-v4-ammap-change-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!