Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 js - how to invert d3.extent

I have drawn my axes in d3 using the d3.extent method to determine the max and min values for the axis.

However, by default, d3 draws the y axis upside down (d3 bar chart is upside down) and I need to invert it.

How to I tell the extent method to invert the results?

like image 984
Neil P Avatar asked Aug 14 '15 09:08

Neil P


1 Answers

You can use d3.extent function in combination with reverse:

var yScale = d3.time.scale()
               .domain(d3.extent(data.History, function (d) { return d.ArrivalTime; }).reverse())
               .range([margin.top, chartHeight - margin.top * 2]);
like image 113
jarandaf Avatar answered Oct 01 '22 12:10

jarandaf