您的问题包括 2 个问题。
1. 身份证:
正如您所指出的,当您使用http://jsoneditoronline.org检查时,您使用的 JSON似乎使用数字作为 ID,因此您目前无法识别哪个形状是 US、FR、HE。最好将此版本与. 我目前手头没有任何 json ,但是您的项目需要英语或 ISO。这几天我在出差。最好和相当容易的是获得具有这两个属性的 JSON 。这很快就会到来。id={country_name_in_english}
iso code
id={country_name_in_english}, iso={iso_code}
2. Vega 选择器:
我还不熟悉 Vega,所以我会将此作为一个纯粹的 D3js 问题来处理如何创建,然后选择正确的形状并根据相关数据为它们着色......
//Create your D3js shapes with the right attributes
var countries = d3.selectAll(".countries")
... // more d3js code creating the countries' shapes here
.attr("id", function(d){ return d.id }) // <= important !
...
// Custom data
var coloring = [ [ "US", "red"], ["FR", "green"], ["HE", "blue"] ];
// Color the given shapes
for (i=0; i < color.length; i++) {
var focus = d3.selectAll("#"+coloring[i][0])
.style("fill", coloring[i][1]);
}
注意:一个纯粹的 Vega 解决方案肯定会更优雅。