javascript - how to start drawing a line with a space between y-axis and it using d3js -


i'm drawing simple line chart axes.

// set scales var x = d3.scale.ordinal()     .domain(data.map(function(d) {         return d.labels;}))     .rangeroundbands([0, width], 0);  var y = d3.scale.linear()     .domain([0, d3.max(data, function(d) { return d.values; })])     .range([height, 0]);  var xaxis = d3.svg.axis().scale(x).orient("bottom"); var yaxis = d3.svg.axis().scale(y).orient("left");  // draw line graph var line = d3.svg.line()     .x(function(d) { return x(d.labels); })     .y(function(d) { return y(d.values); })     .interpolate("linear");  // create svg 'canvas' var svg = d3.select("body").append("svg")         .attr("class", "chart")         .attr("width", width + margin.left + margin.right)         .attr("height", height + margin.top + margin.bottom).append("g")         .attr("transform", "translate(" + margin.left + "," + margin.right + ")");  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")   .attr("d",line(data))   .attr("stroke", color)   .attr("stroke-width", 2)   .attr("fill", "none"); 

here can see works, line starts y-axis values don't correspond labels: http://jsfiddle.net/5r63j/12/ may fixed replacing .rangeroundbands([0, width], 0); .rangepoints([0, width], 0);, values correspond labels , it's quite good, there no padding between y-axis , line.

is possible move start point of line itself?

close not quite! :)

instead of:

.rangepoints([0, width], 0); 

you use

.rangepoints([0, width], 0.5); 

and this:

enter image description here

here jsfiddle.

documentation second parameter of rangepoints() here. illustration parameter meaning:

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -