我已经在我的人力车图中添加了一个日期时间X轴:
var x_axis = new Rickshaw.Graph.Axis.Time({
graph: graph,
timeFixture: new Rickshaw.Fixtures.Time(),
});但是,它通常不会给出我想要的格式。我可以给它一个说明符,这样datetimes总是以指定的格式出现(比如像d3.time.format(说明符) )吗?
发布于 2014-02-12 03:56:58
基于Lars的链接示例,我做了以下工作:
var format = function(d) {
d = new Date(d)
return d3.time.format("%c")(d)
}
var x_axis = new Rickshaw.Graph.Axis.X({
graph: graph,
tickFormat: format,
});这似乎是有效的,所以现在我只需要找到一种方法来使间距出来的好……
发布于 2014-02-22 07:29:51
格式化程序只会格式化字符串,而不会确定间距。为了控制间距和格式,你可以编写你自己的'Fixture',比如看看https://github.com/shutterstock/rickshaw/blob/master/src/js/Rickshaw.Fixtures.Time.js。fixture提供了两个东西:间隔(例如,年、月、日、小时)和每个的格式。根据需要创建类似的夹具、空间和格式,并将其设置在x轴上:
var xAxis = new Rickshaw.Graph.Axis.Time( {
graph: graph,
//timeFixture: new Rickshaw.Fixtures.Time()
timeFixture: new MyOwnTimeFixture()
} );发布于 2017-01-05 03:51:24
试试这个吧,它会起作用的
var xAxis = new Rickshaw.Graph.Axis.Time({
graph: graph,
tickFormat: function(x){
return new Date(x).toLocaleString();
},
ticks: 4
});https://stackoverflow.com/questions/21711362
复制相似问题