问题
I have an Amcharts heatmap chart with a world map. I would like to translate country names in Italian in the balloon text.
I have a file where the names of the countries are translated in Italian, like this var mapTranslations = {"Andorra": "Andorra", "United Arab Emirates": "Emirati Arabi Uniti", "Afghanistan": "Afghanistan", "Bosnia and Herzegovina": "Bosnia Erzegovina", "Barbados": "Barbados", "Bangladesh": "Bangladesh", "Belgium": "Belgio" but I cannot call the translated name in the balloon text.
If I use
"areasSettings": {
"balloonText": "[[title]]: [[value]] sessioni"
},
I see country names in English with the corresponding value, but if I try to call mapTranslations in the balloonText property I get Undefined.
回答1:
AmMaps comes withs its own translations for many languages, including Italian. All you have to do is include the maps' "it.js" translation file and set the language property to "it", for example:
var map = AmCharts.makeChart("mapdiv", {
"type": "map",
"language": "it",
"dataProvider": {
"map": "worldLow",
"getAreasFromMap": true
}
});
#mapdiv {
width: 100%;
height: 300px;
}
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
<script src="https://www.amcharts.com/lib/3/lang-maps/it.js"></script>
<div id="mapdiv"></div>
Note that if you're including the language file directly from the amcharts website you have to use the lang-maps directory. If you're hosting the amcharts files on your webserver, the language files are in the lang directory.
If you need to use your own translation file, I recommend following the amcharts format in the language files and use the language property.
来源:https://stackoverflow.com/questions/45284354/amcharts-heatmap-chart-translate-country-names