d3 simple line graph, showing 'step-after' interpolation
This example shows a problem with the 'step-after' interpolation. It does not draw the 'last' step -- i.e., the step for the last data point.
starting from bostock's example.
then using different interpolation.
and without an url for data.
var myData = "date avg min max\n\
01-Jul-17 344251.9118 10000.0000 1847283.0000\n\
01-Oct-17 244474.6831 10000.0000 1443736.0000\n\
01-Jan-18 334264.7699 33052.0000 1443736.0000\n\
01-Apr-18 348314.0586 15380.0000 2410046.0000\n\
01-Jul-18 202586.6371 14005.0000 2322936.0000\n\
01-Oct-18 140596.8278 14005.0000 2322936.0000\n\
";
var quarter = function (date, i) {
if (i >= 0) {
var date2 = new Date();
date2.setMonth(date.getMonth() - 1);
q = Math.ceil((date2.getMonth()) / 3);
return "Q" + q;
}
};
var margin = {top: 20, right: 20, bottom: 30, left: 60},
width = 400 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var parseDate = d3.time.format("%d-%b-%y").parse;
var x = d3.time.scale()
.rangeRound([0, width],0.8);
//.padding(8.8);
var x2 = d3.time.scale()
.rangeRound([0, width],0.8);
//.padding(0.8);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.ticks(d3.time.months, 3)
.tickSize(5, 0)
.tickFormat(quarter)
.orient("bottom");
var xAxis2 = d3.svg.axis()
.scale(x)
.ticks(d3.time.year,1)
.tickFormat(d3.time.format("%Y"))
.orient("top");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.avg); });
// try this to see interpolation issues.
// Note that the data is "backwards"-going in time.
// Note that with step-after, the last data point (i.e. earliest) shows no "step". Why?
line.interpolate('spline');
// what if we use the defined method of line?
//line.defined(function (d) { return d.close; });
//line.interpolate('step-before');
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top +...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.