문제

I'm in need of a little assistance. I have a stacked area chart in d3.js using ordinal for the x axis (and likely for the y as well but haven't implemented that yet) and while it's rendering, it's not quite right. I need to figure out how to shift the chart (not the axis) so that the left most border is lined up vertically with the first tickmark and the rightmost is even with the last tickmark.

I've tried several variations and can't seem to figure out the starting x value.

Any help would be appreciated.

My x code

var x = d3.scale.ordinal().rangeRoundBands([0, width]);
x.domain(['Dec','Jan','Feb']); // Hard coded for now

var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");

A js fiddle of the entire chart (with data): http://jsfiddle.net/adeaver/FRNbq/6/

도움이 되었습니까?

해결책

Have you tried:

var x = d3.scale.ordinal()
    .rangePoints([0, width]);

That may be what you are looking for.

다른 팁

This also works:

var x = d3.scale.ordinal()
    .rangeRoundBands([0, width], 1, 0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top