像这样的东西应该工作:
var xAxisQPerDay = new Rickshaw.Graph.Axis.X({
graph: graphQPerDay,
tickFormat: function(x) {
switch (x) {
case 1: return 'Mon';
case 2: return 'Tue';
case 3: return 'Wed';
case 4: return 'Thu';
case 5: return 'Fri';
case 6: return 'Sat';
case 7: return 'Sun';
}
}
});
xAxisQPerDay.render();
如果您在侧面构建了地图以缓存字段数据,则可以使用更动态的方法。
var days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
var xAxisQPerDay = new Rickshaw.Graph.Axis.X({
graph: graphQPerDay,
tickFormat: function(x) {
return days[x];
}
});
xAxisQPerDay.render();
或者
var days = { 0: 'Mon', 1: 'Tue', 2: 'Wed', 3: 'Thu', 4: 'Fri', 5: 'Sat', 6: 'Sun' };
var xAxisQPerDay = new Rickshaw.Graph.Axis.X({
graph: graphQPerDay,
tickFormat: function(x) {
return days[x];
}
});
xAxisQPerDay.render();