[英]Setting range and domain for x time axes in d3 js
I am fairly new to d3 js and I still have issues setting the axis. 我对d3 js相当陌生,但在设置轴方面仍然存在问题。 I am trying to set a time axis for a horizontal floating bar chart .
我正在尝试为水平浮动条形图设置时间轴。 My code looks relatively the same with the small exception that from and to are 201808, 201809 etc. (year and month).
我的代码看起来相对相同,但有一个小例外,即往返于201808、201809等(年和月)。
A jsfiddle to the edited code from the example linked below. 通过下面的示例可以轻松地编辑代码。 The changes are in the data set and in:
更改在数据集中和:
var xAxis = d3.axisBottom(x)
.tickFormat(d3.time.format("%Y%b"));
Apparently this is not the smartest way to assign time to an axis, but I am still having issues with the domain, range and scaling of the axes. 显然,这不是将时间分配给轴的最明智的方法,但是我仍然对轴的域,范围和比例有问题。
Your main problem is that you can't mix d3v3 and d3v4 API calls 您的主要问题是您无法混合使用d3v3和d3v4 API调用
Not 不
var xAxis = d3.axisBottom(x)
.tickFormat(d3.time.format("%Y%b"));
But 但
var xAxis = d3.svg.axis().scale(x).orient("bottom");
// .tickFormat(d3.time.format("%Y%b"))
A tip look at your console ans see a possible reason of the problem why you don't see stuff 提示您的控制台的原因是您看不到东西的可能原因
To get a time axis you need to use a time scale and you need to parse the times but they are number so you might could do with 要获取时间轴,您需要使用时间刻度,并且需要解析时间,但是它们是数字,因此您可以使用
function NumberToDate(n) {
return new Date(n/100, (n%100)-1, 1);
}
Julyy
is with one (1) y. Julyy
是一(1)y。
How can May go from the future back in time 怎么可能从未来回到过去
{"month": "May", "to": 201803, "from": 201812}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.