Land,1960,1970,1980,1990,2000,2010,2020,2030,2040,2050,2060,2070,2080
Belgien,9128824,9660154,9855110,9947782,10239085,10839905,11824225,12885338,13918014,14758714,15400272,16027593,16614305
을 지금까지 내가 (그림 참조)
내가 제대로 x 축 레이블을하는 방법을 모르는이 결과를 얻었다.
d3.csv("/Data/temp_eu_popul.csv", function(e, eu_popul) {
console.log(eu_popul);
var years = [1960,1970,1980,1990,2000,2010,2020,2030,2040,2050,2060,2070,2080];
console.log(years);
var population = [];
for(var i = 1960; i<=2080; i+= 10){
population.push(parseFloat(eu_popul[0][i]));
}
console.log(population);
var svg = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500);
var y = d3.scaleLinear()
.domain(d3.extent(population))
.range([250, -50]);
var x = d3.scaleLinear()
.domain([0,years.length])
.range([100, 450]);
var yAxis = d3.axisLeft(y);
svg.append('g')
.attr("transform", "translate(75,150)")
.attr('class', 'y axis')
.call(yAxis);
var xAxis = d3.axisBottom(x);
svg.append('g')
.attr("transform", "translate(0,450)")
.attr('class', 'x axis')
.call(xAxis);
var circles = svg.selectAll("cirle").data(population).enter().append("circle")
.attr("cx", function(d,i){ return x(i); })
.attr("cy", function(d,i){ return 350-y(d); })
.attr("r", 2);
});
내가 갈 수있는 방법은 변경하는 것입니다 thougth :
var x = d3.scaleLinear()
.domain(d3.extent(years))
.range([100, 450]);
var circles = svg.selectAll("cirle").data(population).enter().append("circle")
.attr("cx", years)
.attr("cy", function(d,i){ return 350-y(d); })
.attr("r", 2);
});
또 다른 한가지는 내가 년 동안 별도의 배열을 만든, 여기에 지금까지 내 코드입니다. 하지만 그 문제를 해결할 더 좋은 방법이있을 것입니다. 년이 이미 CSV 파일에 있기 때문에. 여분의 배열을 만들지 않고 어떻게 든 사용할 수 있습니까?
hm, x = d3.scaleOrdinal(). domain (years) .range ([최소, 최대]) 코드로 변경하면 빈 페이지가 나타납니다. 범위 ([최소, 최대])를 .range ([100, 450])로 다시 변경하십시오. 출력이 나오지만 이상하게 보입니다. min, max는 d3에 미리 정의되어 있습니까? 그렇다면 내 코드는 최소값과 최대 값을 알고 있습니까? – obrob
죄송합니다. 분과 맥스를 자신의 가치로 대체해야한다고 말씀 하셨어야합니다! – danimal
지금 편집 됨, 위를 참조 – danimal