1
그리드 선이 x 축의 마지막 항목에서 끝나지 않지만 선 그래프의 뒷면에 그리드 선을 추가하려고합니다. 아래의 plnk를 참조하십시오. 참조 d3.js 격자 선이 x 축 위에 매달려 있습니까?
http://plnkr.co/edit/j8qQ19m4l4jgdCsRu1da?p=preview
, 나는 이런 식으로 뭔가를 찾고 있어요;있지만, 나는 중앙으로 라인 차트를 밀어 x 축에 빈 항목을 추가하는 것이 얼마나 쉬운 모르겠어요.
어쨌든 누군가가이 문제를 해결할 수 있기를 바랍니다.
감사
JS
var x = d3.time.scale()
.domain([new Date(2016, 0, 1), new Date(2016, 11, 31)])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, 100])
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.months)
.tickFormat(d3.time.format("%B"))
.tickSize(-height, 0, 0)
.innerTickSize(-height)
.tickPadding(15)
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.innerTickSize(-width)
.outerTickSize(0)
.tickPadding(15)
.tickSize(-width, 0, 0)
var line = d3.svg.line()
.x(function(d) {
return x(new Date(2016, moment(d.date, 'MMMM').format('M') - 1, 1));
})
.y(function(d) {
return y(d.close);
});
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.tsv("data.tsv", type, function(error, data) {
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", line);
});
function type(d) {
d.date = d.date;
d.close = +d.close;
return d;
}
TSV으로 인해 dates.You에
는date close
January 50
February 100
March 75
April 90
May 85
June 40
July 30
August 35
September 12
October 72
November 77
December 5
하나의 작은 일이 있었어야 '.domain ([새 날짜 (2016, 0, 1), 새로운 날짜 (2016, 11, 1)]) 11 월 30 일 P : – Cyril
@Cyril 하하 내가 그 중 하나를 놓친 것 같아요 : L – thatOneGuy