score:2

Accepted answer

one possible solution is to add years to date field like this

{
    date: "2010-october",
    price: "100"
}

if you are not going to display the year, it may be arbitrary, just make sure, that after december it increases by 1.

then replace var parsedate = d3.time.format("%b"); with var parsedate = d3.time.format("%y-%b");

also replace .call(xaxis.ticks(d3.time.year)); with .call(xaxis.ticks(d3.time.months));

here is the fiddle: https://jsfiddle.net/p68z0bqo/


edit: if you can't add years manually, you can try to do this automatically like this:

var parsedate = d3.time.format("%y-%b");
data.foreach(function(d) {
  var year = 2000;
  d.values.foreach(function(d) {
    if (d.date === 'january') year++;
    d.date = parsedate.parse(year.tostring() + '-' + d.date);
    d.price = +d.price;
  });
});

this code only works if all months are present (there are no gaps) and if january is represented exactly as "january" (i.e. it has the same case).


Related Query

More Query from same tag