javascript jvectormap 区域颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12867615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jvectormap region colors
提问by Navigatron
Im using the jvectormap plugin, and I am trying to set the colors of each of the regions on the map. However, after applying the code below the map is displayed but with no colours applied. It just shows the map in white.
我使用jvectormap 插件,我试图设置地图上每个区域的颜色。但是,在应用下面的代码后,会显示地图但没有应用颜色。它只是以白色显示地图。
I have read multiple examples and questions on this matter, but I cant seem to get it to work for me.
我已经阅读了关于这个问题的多个例子和问题,但我似乎无法让它对我来说有效。
Example 1of setting random colours on a map.
在地图上设置随机颜色的示例 1。
Similar questionto mine, however it doesn't solve my problem.
jQuery('#mapDiv').vectorMap({
map: 'au_merc_en',
backgroundColor: 'none',
colors: {
AU-SA: '#4E7387',
AU-WA:'#333333',
AU-VIC:'#89AFBF',
AU-TAS:'#817F8E',
AU-QLD:'#344B5E',
AU-NSW:'#344B5E',
AU-ACT:'#344B5E',
AU-NT:'#344B5E'
},
series: {
regions:
[{
attribute: 'fill'
}]
}
});
Can anyone see the problem?
任何人都可以看到问题吗?
回答by mg1075
Here is a working sample of what I think you're attempting to do.
这是我认为您正在尝试做的工作示例。
(function() {
var myCustomColors = {
'AU-SA': '#4E7387',
'AU-WA': '#333333',
'AU-VIC': '#89AFBF',
'AU-TAS': '#817F8E',
'AU-QLD': '#344B5E',
'AU-NSW': '#344B5E',
'AU-ACT': '#344B5E',
'AU-NT': '#344B5E'
};
map = new jvm.WorldMap({
map: 'au_merc_en',
container: $('#ausie'),
backgroundColor: '#eff7ff',
series: {
regions: [{
attribute: 'fill'
}]
}
});
map.series.regions[0].setValues(myCustomColors);
})();
This example builds off of two examples on the jvectormap site:
1. http://jvectormap.com/maps/countries/australia/
2. http://jvectormap.com/examples/random-colors/
此示例基于 jvectormap 站点上的两个示例:
1. http://jvectormap.com/maps/countries/australia/
2. http://jvectormap.com/examples/random-colors/
The fiddle includes the jvectormap 1.1 file from the site. Also note the Random Colors example on the site uses jvm.WorldMap.
小提琴包括来自站点的 jvectormap 1.1 文件。另请注意站点上的随机颜色示例使用 jvm。世界地图。
回答by CBusBus
The code below has been edited to fix the syntax errors in your posted code.
下面的代码已被编辑以修复您发布的代码中的语法错误。
jQuery('#mapDiv').vectorMap({
map: 'au_merc_en',
backgroundColor: 'none',
colors:{
"AU-SA": '#4E7387',
"AU-WA":'#333333',
"AU-VIC":'#89AFBF',
"AU-TAS":'#817F8E',
"AU-QLD":'#344B5E',
"AU-NSW":'#344B5E',
"AU-ACT":'#344B5E',
"AU-NT":'#344B5E'
},
series: {
regions:
[{
attribute: 'fill'
}]
}
});
Unbound (closest antonym of encapsulated I can muster) hyphens within object keys cause a syntax error. The error itself is for an invalid label.
对象键中的未绑定(我可以召集的最接近的封装的反义词)连字符会导致语法错误。错误本身是针对无效标签的。