简体   繁体   English

需要帮助在D3.js条形图中用条形排列x轴刻度

[英]Need help lining up x axis ticks with bars in D3.js bar chart

I have a working linear bar chart using D3.js , which also has time-based x axis. 我有一个使用D3.js的工作线性条形图,它也有基于时间的x轴。 The bars are bound to a count attribute, while the axis is bound to a date attribute. 条形图绑定到count属性,而轴绑定到日期属性。 The ticks in the axis are not lining up with the bars. 轴上的刻度不与条形排列。 Any idea how to line them both up? 知道如何将它们排成两行吗?

Here's the jsFiddle: http://jsfiddle.net/MmEjF/ 这是jsFiddle: http//jsfiddle.net/MmEjF/

This is happening because the chart has 14 bars, but 15 tick marks. 发生这种情况是因为图表有14个条形,但有15个刻度线。

The first tick mark should be the month prior to the start of your data set. 第一个刻度标记应该是数据集开始之前的月份。

You can fix this by pulling forward the start of xTimeDomain by one month: 你可以通过将xTimeDomain的开头提前一个月来解决这个问题:

xTimeDomain[0] = new Date(new Date(xTimeDomain[0]).setMonth(xTimeDomain[0].getMonth()-1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM