D3.extent问题与月份的第一天和最后一天的月值混淆(D3.extent issues with month value confusion over first and last day of

编程入门 行业动态 更新时间:2024-10-26 01:22:44
D3.extent问题与月份的第一天和最后一天的月值混淆(D3.extent issues with month value confusion over first and last day of month)

我已经为我的问题创建了一个Plunkr,可以在链接中找到

我在使用月份值时遇到缩放问题。 我相信这是一个简单的解决方案。

我的问题的可视化如下(看12月):

简而言之,当在轴和条的更新模式中使用d3.extent时,d3不能正确计算域。 它似乎认为它比它小,所以我有一个条目太多,导致一个条挂起,x轴是一个值太长。

我的xScale正常计算:

xScale = d3.time.scale() .domain(d3.extent(data,function(d){return d.funded_month})) .rangeRound([0, (w + offsetBar) - (marginleft + marginright)]);

x轴,条形图和文本都在同一个域中工作。

可视化所有年份时,viz正确显示:

问题是每个相应可视化中的值的数量是不同的(13年对12个月?错误是什么?

I have created a Plunkr for my issue, found at the link

I am having a problem with scaling when using month values. I am sure this is a simple fix.

A visualization of my issue is below (look at December):

In short, when using d3.extent in an update pattern for the axis and the bars, d3 is not computing the domain correctly. It seems to think it is less than it is and so I have one entry too many, leading one bar to hang off and the x axis to be one value too long.

My xScale is computed normally:

xScale = d3.time.scale() .domain(d3.extent(data,function(d){return d.funded_month})) .rangeRound([0, (w + offsetBar) - (marginleft + marginright)]);

Both the x Axis, bars and text are all working off the same domain.

When visualizing all years, the viz appears correctly:

Is the issue that the number of values in each respective visualization are different (13 years vs 12 months? What is the mistake?

最满意答案

我无法使用现有库实现简单的解决方案。

因为D3解释“月,年”格式,假设日是午夜的第一个月,1月到12月仅被认为是11个月。

所以我每个月都会创造一个平滑的轴:

2001-01-01,68991364 2001-02-04,554541108 2001-03-07,151123291 2001-04-10,283000000 2001-05-12,8093737 2001-06-15,55718802 2001-07-18,95060100 2001-08-21,78000000 2001-09-23,150000000 2001-10-25,193330000 2001-11-28,59948530 2001-12-31,142424927

我能够在我的轴文本上使用x translate与条形图同步移动。

迈克博斯托克在这里进一步研究这个问题。

I was not able to implement an easy solution with existing libraries.

Because D3 interprets the "Month, Year" format assuming the day is the first of the month at midnight, January to December is considered only 11 months.

So I stepped the days of every month to create a smooth axis:

2001-01-01,68991364 2001-02-04,554541108 2001-03-07,151123291 2001-04-10,283000000 2001-05-12,8093737 2001-06-15,55718802 2001-07-18,95060100 2001-08-21,78000000 2001-09-23,150000000 2001-10-25,193330000 2001-11-28,59948530 2001-12-31,142424927

I was able to use an x translate on my axis text to move in sync with the bars.

Mike Bostock goes further into this issue here.

更多推荐

本文发布于:2023-07-31 02:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天和   extent   issues   day   confusion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!