gpt4 book ai didi

jVectorMap 着色在某些国家/地区失败

转载 作者:行者123 更新时间:2023-12-02 00:15:25 29 4
gpt4 key购买 nike

我正在使用 jVectorMap 通过着色显示国家/地区值(即,国家/地区根据其值使用不同的颜色)。一切正常,除非某些国家/地区包含在数据集中。然后这些国家并没有像他们应该的那样被着色(事实上,它们根本就没有被着色)。

我已将巴林 (BH) 和新加坡 (SG) 确定为破坏 map 的两个国家/城邦。看起来好像这些国家不在 map 上。我对他们不在场并不感到惊讶。但是,我希望 map 不会失败。

'this.elements[...].element' is null or not an object 的 JavaScript 错误在于以下内容(请参阅下面代码中有关失败的注释)。

jvm.DataSeries.prototype={
//...
setValues:function(e){
var t=Number.MIN_VALUE,n=Number.MAX_VALUE,r,i,s={};
if(!this.params.min||!this.params.max){
for(i in e)
r=parseFloat(e[i]),r>t&&(t=e[i]),r<n&&(n=r);
this.params.min||this.scale.setMin(n),this.params.max||this.scale.setMax(t),this.params.min=n,this.params.max=t
}
for(i in e)
//FAILS ON THE FOLLOWING LINE
r=parseFloat(e[i]),r?s[i]=this.scale.getValue(r):s[i]=this.elements[i].element.style.initial[this.params.attribute];
this.setAttributes(s),this.values=e
},
//...
},

有没有办法解决这个问题?我宁愿更改 jVectorMap 代码,或者必须在我的 Java 代码中执行如下操作:

if (!countryCode.equals("BH") && !countryCode.equals("SG")) {
countryValues.put(countryCode, countryValue);
}

最佳答案

如果您想确保您的数据仅包含 map 中的国家/地区代码,您可以在设置 map 数据之前使用 map 国家/地区代码作为过滤条件来过滤数据。

您可以定义一个方法,在该方法中传入数据、遍历每个项目并删除 map 路径中不存在国家代码的条目:

function filterDataForMap(data, mapName){
var filteredData = {};
$.each(data,function(key, value){
//Only add when the key (country code) exists in the map
if(jvm.WorldMap.maps[mapName].paths[key]!==undefined) {
filteredData[key] = value;
}
});
return filteredData;
}

应用于 map 的制作:

$('#map').vectorMap({
map: 'world_mill_en',
series: {
regions: [
{
scale: colorScale,
attribute: 'fill',
normalizeFunction: 'polynomial',
values: filterDataForMap(mapData, 'world_mill_en') //filter data
}]
}
});

关于jVectorMap 着色在某些国家/地区失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13406062/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com