如何在xaxis jquery flot上时间为12:00 AM时显示日期

时间:2012-05-17 07:57:52

标签: jquery flot

我想标记jquery.flot图表的x轴,以1小时为增量显示时间。当时间过了午夜时,我想显示日期和时间。

我该怎么做?

由于

2 个答案:

答案 0 :(得分:2)

您可以将tickSize(或minTickSize,取决于您希望标签的行为方式)设置为[1, "hour"],然后提供生成标签的tickFormatter函数日期是午夜,否则是空字符串。

答案 1 :(得分:1)

正如DNS建议的那样,请使用tickFormatter。类似的东西:

tickFormatter: function formatter(val, axis) {
  var d = new Date(val);
  var rV = null;          
  if (lastDay == null) //lastDay is a global, set to null outside of plot call
  {
    rV = $.plot.formatDate(d, "%H:%M"); // first date return time
  }
  else
  {
     if (d.getDay() == 1 || d.getDay() > lastDay.getDay())  // we have a new day
     {
     rV = $.plot.formatDate(d, "<b>New Day</b></br> %m/%d"); // return different format
     }
     else  // same day, just time
     {
     rV = $.plot.formatDate(d, "%H:%M");
     }
  }
  lastDay = d; 
  return rV;
}