I want to create a colored map for Malaysia but the colors don't display. I've used the names from the file my.js which works for other countries with google geochart. Why won't it work?
function drawMap() {
var data = google.visualization.arrayToDataTable([
['Province'],
['MY-SK'],
['MY-K'],
['MY-M'],
['wilayah persekutuan labuan'],
['wilayah persekutuan putrajaya'],
['negeri sembilan']
]);
//var results = {"sarawak": "MY-SK", "melaka": "MY-M", "kedah": "MY-K", "wilayah persekutuan labuan": "MY-L", "wilayah persekutuan putrajaya": "MY-16", "negeri sembilan": "MY-N", "johor": "MY-J", "kelantan": "MY-D", "perlis": "MY-R", "sabah": "MY-SA", "wilayah persekutuan kuala lumpur": "MY-W", "pulau pinang": "MY-P", "terengganu": "MY-T", "pahang": "MY-C", "perak": "MY-A", "selangor": "MY-B"};
var options = {
region: 'MY',
backgroundColor: '#81d4fa',
datalessRegionColor: '#ffc801',
width: 468,
height: 278,
resolution: 'provinces',
};
var container = document.getElementById('mapcontainer');
var chart = new google.visualization.GeoChart(container);
function myClickHandler() {
var selection = chart.getSelection();
var message = '';
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
// if (item.row != null && item.column != null) {
message += '{row:' + item.row + ',column:' + item.column + '}';
//} else
if (item.row != null) {
message += '{row:' + item.row + '}';
//} else if (item.column != null) {
// message += '{column:' + item.column + '}';
}
}
if (message == '') {
message = 'nothing';
}
//alert('You selected ' + message);
}
google.visualization.events.addListener(chart, 'select', myClickHandler);
chart.draw(data, options);
}
google.load('visualization', '1', {
packages: ['geochart'],
callback: drawMap
});
The regions that belong to Malaysia should get colored green as they do for other countries. Why don't they?
I also had this kind of problem and though I don't have exact explanation why the problem happened, you can try this workaround to use the ISO_3166-2 representation of malaysian provinces rather than its name directly.
var data = google.visualization.arrayToDataTable([
['Province', 'Name'],
['MY-15', 'wilayah persekutuan labuan'],
['MY-16', 'wilayah persekutuan putrajaya'],
['MY-05', 'Negeri Sembilan']
]);