javascript - d3 Line Chart Filling at Arbitrary Line -



javascript - d3 Line Chart Filling at Arbitrary Line -

i'm attempting create simple line chart d3, reason it's filling between line , midpoint. here's output:

my javascript following:

var width = 500, height = 500, padding = 10; var extentvisits = d3.extent(visits, function(obj){ homecoming obj['visits']; }); var extentdates = d3.extent(visits, function(obj){ homecoming obj['datestamp']; }); var yscale = d3.scale.linear() .domain(extentvisits) .range([height - padding, padding]); var xscale = d3.time.scale() .domain(extentdates) .range([0, width]); var line = d3.svg.line() .x(function(d) { homecoming xscale(d['datestamp']); }) .y(function(d) { homecoming yscale(d['visits']); }) d3.select('#chart') .append('svg') .attr('width', width) .attr('height', height) .append("g") .attr("transform", "translate(5,5)") .append('path') .datum(visits) .attr("class", "line") .attr('d', line);

where visits of form:

visits = [{'datestamp': timestampa, 'visits': 1000}, {'datestamp': timestampb, 'visits': 1500}]

i'm pretty new @ d3 i'm sure it's simple, it's driving me crazy.

thanks in advance.

the midpoint you're seeing connection of first , lastly point. because path you've created has (by default) black fill. though it's open path (i.e., first , lastly point not connected), if filled, appear closed:

the fill operation fills open subpaths performing fill operation if additional "closepath" command added path connect lastly point of subpath first point of subpath.

source: svg specification via this answer

the solution here eliminate fill , instead set stroke. can straight in js d3 or through css.

path.line { fill: none; stroke: #000; }

demo showing both css , js method (commented out) on jsfiddle

javascript d3.js

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -