I am plotting a d3 graph in which my data is coming from json and on x axis I am having dates but those dates are not coming in ascending order means those dates are not sorted. I have used the sort function but its not working because even after applying this sort function I am not getting sorted dates. Here is my snippet where I used sort function
if (filterByDates) {
selectDate = true;
tempData = fliterdata;
console.log("before date fliter data", tempData);
var date1 = new Date(document.getElementById('field1').value);
var date2 = new Date(document.getElementById('field2').value);
tempData = tempData.filter(function(d) {
console.log(date1, date2);
// alert(date1);
return d.date >= date1 && d.date <= date2;
});
console.log("After date fliter data", tempData);
}
xScale.domain(tempData.map(function(d) {
return d.date;
}).sort(function(a, b) {
return a > b;
}));