0
y 축의 가격과 x 축의 날짜를 사용하여 선형 차트를 그리려고합니다.d3.svg.line(). x 함수가 호출되지 않았습니다.
하는 실행시 :..
.attr("d", function(d){
console.log(line(d.closePrice));
return line(d);
});
라인 (d.closePrice가) 널 (null)와 d3.svg.line() 반환 ×() 및 d3.svg.line() Y 것은 호출되지 않습니다. d3.scale.linear()를 사용하는 유사한 작업 예제가 있는데 코드가 실패하게 만드는 원인을 파악할 수 없습니다.
var x = d3.time.scale()
.domain([new Date(closes[0].closeDate), new Date(closes[closes.length - 1].closeDate)])
.range([margin, width - margin]);
var y = d3.scale.linear()
.domain([closePriceMin, closePriceMax])
.range([height - margin, margin]);
var line = d3.svg.line()
.x(function(d) {
console.log("line x called");
return x(new Date(d.closeDate));
})
.y(function(d) {
console.log("line y called");
return y(d.closePrice);
});
var svg = d3.select("body").append("svg");
svg.attr("height", height)
.attr("width", width);
svg.selectAll("path")
.data(closes)
.enter()
.append("path")
.attr("class", "line")
.attr("d", function(d){
console.log(line(d.closePrice));
return line(d);
});
내가 사용하여 파일에서 JSON을 얻고있다 :
d3.json("data.json", function(error, json){
for(var close in json){
closes.push(json[close]);
JSON 형식 :
[{
"id": 6031839,
"equityId": 52597,
"closeDate": "Apr 8, 2016",
"closePrice": 12.73,
"sma12Day": 13.891666666666664,
"sma26Day": 13.184230769230773,
"ema12Day": 12.533611111111112,
"ema26Day": 12.696952662721895,
"macd": -0.1633415516107828,
"macdSignal": -0.17577601845764257,
"macdHistogram": 0.012434466846859782,
"openPrice": 12.91,
"high": 12.91,
"low": 12.72,
"volume": 22700,
"closePeak": false,
"closeTroff": false,
"macdPeak": false,
"macdTroff": false
}, {
"id": 6030002,
"equityId": 52597,
"closeDate": "Apr 7, 2016",
"closePrice": 12.61,
"sma12Day": 13.908333333333331,
"sma26Day": 13.159615384615385,
"ema12Day": 12.385416666666666,
"ema26Day": 12.570059171597633,
"macd": -0.18464250493096657,
"macdSignal": -0.17599694807672042,
"macdHistogram": -0.008645556854246145,
"openPrice": 12.78,
"high": 12.78,
"low": 12.6,
"volume": 20700,
"closePeak": false,
"closeTroff": true,
"macdPeak": false,
"macdTroff": true
}]
의 변화를 했습니까? 그래서 내가 볼 수있다 –
업데이트를 참조하십시오 – user2670815