2013-06-13 4 views
0

이 bl.ocks 내 d3.js지도입니다 연도에 따라 JSON지도를 전환 http://bl.ocks.org/textplusdata/f64f54dd8c1a0b632ed5 당신은 시간이 지남에 따라 변화를 보여 년간의 데이터를 순환 화살표 키 또는 자동 재생을 사용할 수있는 원시 버전에d3.js 여기

.

내 질문은 여기 있습니다. 어떻게하면 올해에 따라 다른 세계 json 파일을로드 할 수 있습니까? 1991 년 이전에는 옛 소련이 존재하지만 그 자료에는 나타나지 않는다.

이미 두 개의 jsons가 업로드되어 있습니다. 하나는 오래된 소련 노조가 있고 다른 하나는 제외 된 것입니다.

// The map 

var maptype; 
if (parseInt(year) < 1991) maptype = world_countriesold; 
if (parseInt(year) > 1991) maptype = world_countries; 


var countries = d3.select("g#countries").empty() ? 
chart.append("g").attr("id", "countries") : d3.select("g#countries"), 
country = countries 
.selectAll("path") 
.data(maptype.features); 
country 
.enter() 
.append("path") 
.classed("country", true) 
// changed { return d.id; } to { return d.ISO1AL3; } to look up 3-letter country code in c-shapes json 
.attr("id", function(d,i) { return d.id; }) 
// changed { return d.properties.name; } to { return d.properties.CNTRY_NAME; } to return correct field in c-shapes json 
.attr("title", function(d,i) { return d.properties.name; }) 
.attr("d", path); 

난 그냥 넣어 가지고 추측

답변

0

... 문 잘못된 장소에서 "만약",하지만 난 방아쇠를 강제하는 방법을 알고하지 않는 경로의 초기 생성 한 후, 새 데이터를 전달할 때 기존 데이터를 업데이트해야합니다. 업데이트에 대한 귀하의 코드는 코드 블록을 당신이 if 문 블록 내에서 maptype, 즉를 변경할 때마다 호출 할 필요가 뭔가

country = countries.selectAll("path") 
    .data(maptype.features); 

country.enter() 
    .append("path"); 
country.classed("country", true) 
    .attr("id", function(d,i) { return d.id; }) 
    .attr("title", function(d,i) { return d.properties.name; }) 
    .attr("d", path); 
country.exit().remove(); 

처럼 보일 것입니다.