0

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

我怎样才能做到这一点?

谢谢

4

2 回答 2

2

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

于 2012-05-17T09:42:01.780 回答
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;
}
于 2012-05-17T18:02:31.853 回答