0

有一个日期范围,例如 2013-07-01 到 2013-07-18。我想显示两个日期之间的日期。我还设置了 min=2013-07-01,max=2013-07- 18,tickInterval=7 天。但是 X 轴将是 2013-07-01,2013-07-08,2013-07-15,2013-07-22。我只想显示到 2013-07-18 的数据.我可以做点什么让X轴是2013-07-01,2013-07-08,2013-07-15,2013-07-18?????非常感谢..

4

1 回答 1

0

如果您的刻度永远不会改变,您可以告诉 jqplot 使用字符串数组作为刻度标签:

var xTicks = ['2013-07-01', '2013-07-08', '2013-07-15', '2013-07-18'];
$.jqplot('chart1', [myData], {
 axes: {
  xaxis: {
   renderer:$.jqplot.DateAxisRenderer, 
   rendererOptions:{
    tickRenderer:$.jqplot.CanvasAxisTickRenderer
   },
   ticks: xTicks, 
   tickOptions: {
    angle: -90,
    formatString: '%d/%m/%Y %H:%M'
   },
  }
 }
});

请在此处查看工作 jsFiddle

编辑

更新了 jsFiddle,用于为包含从 2013-07-01 到 2013-07-18 的所有日期的数组 xDates 制作xTicks

var dates = [
 '2013-07-01','2013-07-02','2013-07-03','2013-07-04',
 '2013-07-05','2013-07-06','2013-07-07','2013-07-08',
 '2013-07-09','2013-07-10','2013-07-11','2013-07-12',
 '2013-07-13','2013-07-14','2013-07-15','2013-07-16',
 '2013-07-17','2013-07-18',
];
var nbWeeks = Math.floor(dates.length/7);
var xTicks = [];
xTicks.push(dates[0]);
for(var i = 1; i<=nbWeeks; i++)
 xTicks.push(dates[i*7]);
xTicks.push(dates[dates.length-1]);
于 2013-08-12T13:45:03.920 回答