Date 在nvd3.js中格式化日期
如何在nvd3.js中设置日期格式。例如:Date 在nvd3.js中格式化日期,date,format,nvd3.js,Date,Format,Nvd3.js,如何在nvd3.js中设置日期格式。例如: data1 = [{ "values": [{ "x": 1374561814000, "y": 2 }], "key": "x-axis" }] 1374561814000它是什么意思,它是如何从日期转换而来的?日期1374561814000当前是Unix时间戳 您可以定义在将日期传递到图表中时,希望日期在图表中的显示方式。阅读d3指南会让你更好地理解它 chart.xAxis.tickFormat(function(d
data1 = [{
"values": [{
"x": 1374561814000,
"y": 2
}],
"key": "x-axis"
}]
1374561814000
它是什么意思,它是如何从日期转换而来的?日期1374561814000
当前是Unix时间戳
您可以定义在将日期传递到图表中时,希望日期在图表中的显示方式。阅读d3指南会让你更好地理解它
chart.xAxis.tickFormat(function(d) {
// Will Return the date, as "%m/%d/%Y"(08/06/13)
return d3.time.format('%x')(new Date(d))
});
或者,您可能希望返回显示日期/月/年的日期戳,为此,您只需执行以下操作:
return d3.time.format('%d/%m/%y')(new Date(d))
假设您希望unix时间戳以分钟和小时为单位返回日期,它将是:
return d3.time.format('%X')(new Date(d)) // Capital X
以上示例已经过测试,请使用下面的值进行模拟()
希望能有帮助
如果其他成员认为这需要改进,请继续改进答案。我理解。谢谢你的帮助。在x轴上,日期以d/m/y格式显示。但是,当我试图将鼠标移到某个特定坐标上时,它会显示NaN/NaN/NaN。可能是什么问题?
Constructs a new local time formatter using the given specifier. The specifier string may contain the following directives.
- %a - abbreviated weekday name.
- %A - full weekday name.
- %b - abbreviated month name.
- %B - full month name.
- %c - date and time, as "%a %b %e %H:%M:%S %Y".
- %d - zero-padded day of the month as a decimal number [01,31].
- %e - space-padded day of the month as a decimal number [ 1,31]; equivalent to %_d.
- %H - hour (24-hour clock) as a decimal number [00,23].
- %I - hour (12-hour clock) as a decimal number [01,12].
- %j - day of the year as a decimal number [001,366].
- %m - month as a decimal number [01,12].
- %M - minute as a decimal number [00,59].
- %L - milliseconds as a decimal number [000, 999].
- %p - either AM or PM.
- %S - second as a decimal number [00,61].
- %U - week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
- %w - weekday as a decimal number [0(Sunday),6].
- %W - week number of the year (Monday as the first day of the week) as a decimal number [00,53].
- %x - date, as "%m/%d/%Y".
- %X - time, as "%H:%M:%S".
- %y - year without century as a decimal number [00,99].
- %Y - year with century as a decimal number.
- %Z - time zone offset, such as "-0700".
- %% - a literal "%" character.