Reputation: 2169
This seems like a basic question, however, I can't seem to find the answer in the documentation or here on stackoverflow.
I'm trying to get the translated country names for my map that I generated with amcharts4.
I found this related question, however, this is specified for amcharts3. When I try to set the language property of a chart series like this in amcharts4,
chart.language = 'nl';
,
I get the error Uncaught TypeError: Cannot read property 'on' of undefined
which I believe is the standard error for when you set an unsupported property.
I also found this related question, which says you should set chart.language.locale
, this works for amcharts4, but does not translate the country names. This only translates the used units and dates etc.
So my questions is, "How do I change the country names for a generated map in amcharts4?"
Upvotes: 1
Views: 711
Reputation: 2169
So, the official answer from amcharts is this:
No, I'm afraid. We currently do not have a ready-made solution for country name translations :(
What I did was grab a translation json file from this repository.
I did a find and replace to remove the property and value of property id
.
I changed the property name alpha2
to id
, and converted it's value to uppercase.
So for instance
{"id":4,"name":"Afghanistan","alpha2":"af","alpha3":"afg"}
Will become
{"name":"Afghanistan","id":"AF","alpha3":"afg"}
This will then essentialy become your translation object.
I then declared a variable translations
and gave it this complete object as a value.
I then added this as data to my polygonSeries. polygonSeries.data = translations;
.
Because this now overwrites the name property with the translated value, the hover effects should be with the translated value.
Upvotes: 1