admin管理员组文章数量:1401963
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?
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?
Share Improve this question edited May 23, 2017 at 12:00 CommunityBot 11 silver badge asked Aug 14, 2015 at 9:39 Neil PNeil P 3,2107 gold badges41 silver badges76 bronze badges 4- show us what you have tried so far, ideally with some fiddle or similar – jarandaf Commented Aug 14, 2015 at 10:11
- I've managed to find a way to make it work, but was wondering if there was a single function to do it! – Neil P Commented Aug 14, 2015 at 10:22
-
2
Ok, now I understand... a one-liner:
d3.time.scale().domain(d3.extent(data.History, function (d) { return d.ArrivalTime; }).reverse())
... – jarandaf Commented Aug 14, 2015 at 10:25 - reverse! Makes perfect sense. Do you want to drop that into an answer so I can mark it? – Neil P Commented Aug 14, 2015 at 10:26
2 Answers
Reset to default 8You can use d3.extent function in bination 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]);
I've managed to do it manually using the following code. I can't find a neater way than this:
var yMax = d3.max(data.History, function (d) { return d.ArrivalTime });
var yMin = d3.min(data.History, function (d) { return d.ArrivalTime });
var yScale = d3.time.scale()
.domain([yMax, yMin])
.range([margin.top, chartHeight - margin.top * 2]);
本文标签: javascriptd3 jshow to invert d3extentStack Overflow
版权声明:本文标题:javascript - d3 js - how to invert d3.extent - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744334810a2601138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论