我正在使用此功能如下:
let colors = < any > {};
let colors = {
"zz": "#006491",
"us": "#1a769f",
"nl": "#bde6f9",
"at": "#c0e8fa",
"tr": "#c0e8fa",
"ie": "#c0e9fb"
}
jQuery('#vmap').vectorMap('set', 'colors', colors);
并且可能你需要不同的颜色(我需要:))例如根据一些值你可以计算一些起始颜色并用最小值和最大值计算
let myValuesMap: Map<string, number> = new Map(); //{"zz" => 3011, "us" => 2669, "at" => 260, "nl" => 172, "tr" => 148, "ie"=>101}
let max = 0, min = Number.MAX_VALUE, startColor = [200, 238, 255], endColor = [0, 100, 145], colors = <any>{}, hex;
myValuesMap.forEach((value: number, key: string) => {
if (value > max) { max = value }
if (value < min) { min = value }
});
myValuesMap.forEach((value: number, key: string) => {
if (value > 0) {
colors[key] = '#';
for (var i = 0; i < 3; i++) {
hex = Math.round(startColor[i] + (endColor[i] - startColor[i]) * (value == max ? 1 : (value / (max - min)))).toString(16);
if (hex.length == 1) { hex = '0' + hex; }
colors[key] += (hex.length == 1 ? '0' : '') + hex;
}
}
});
jQuery('#vmap').vectorMap('set', 'colors', colors);