2012-08-09 34 views
5

我想使用jQPlot和將呈現的軸線爲一系列的日期值 - jQPlot的原始包裝可以是字體的位置:爲什麼jQPlot dateAxisRenderer工作不正確?

http://www.jqplot.com/

http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

問題是這樣的:

一)x軸的左側沒有開始,也將表明,我不希望看到值

b)只是在相同的問題上有更多不需要的號碼

c)我想在xaxis上有所有的日子1 2 3 4 5 ...不是31 3 6 9 ...

d)是可以設置一種偏移底部(只是一點點...)

截圖: Picture from current status

我的代碼:

$.jqplot('chartdiv', [ 
    [ 
     ['2012-08-01', 0], 
     ['2012-08-02', 0], 
     ['2012-08-03', 0], 
     ['2012-08-04', 0], 
     ['2012-08-05', 0], 
     ['2012-08-06', 0], 
     ['2012-08-07', 1], 
     ['2012-08-08', 0], 
     ['2012-08-09', 6], 
     ['2012-08-10', 0], 
     ['2012-08-11', 0], 
     ['2012-08-12', 0], 
     ['2012-08-13', 0], 
     ['2012-08-14', 0], 
     ['2012-08-15', 0], 
     ['2012-08-16', 0], 
     ['2012-08-17', 0], 
     ['2012-08-18', 0], 
     ['2012-08-19', 0], 
     ['2012-08-20', 0], 
     ['2012-08-21', 0], 
     ['2012-08-22', 0], 
     ['2012-08-23', 0], 
     ['2012-08-24', 0], 
     ['2012-08-25', 0], 
     ['2012-08-26', 0], 
     ['2012-08-27', 0], 
     ['2012-08-28', 0], 
     ['2012-08-29', 0], 
     ['2012-08-30', 0], 
     ['2012-08-31', 0] 
    ] 
], { 
    title: 'Downloadstatistik', 
    axes: { 
     xaxis: { 
      renderer: $.jqplot.DateAxisRenderer, 
      tickOptions: { 
       formatString: '%#d', 
       tickInterval: '1 month' 
      }, 
      pad: 1.0 
     }, 
     yaxis: { 
      tickOptions: { 
       formatString: '%.0f' 
      }, 
      min: 0 
     } 
    } 
}); 

回答

10

開始時,你應該嘗試設置你的tickInterval爲「1日」 :)

在此之後,關鍵是要設置爲根據您的日期數組的第一個和最後一個值的x軸的最小值和最大值。

下面是一個例子:

var timeline = [[ 
    ['2012-08-01', 0], ['2012-08-02', 0], ['2012-08-03', 0], 
    ['2012-08-04', 0], ['2012-08-05', 0], ['2012-08-06', 0], 
    ['2012-08-07', 1], ['2012-08-08', 0], ['2012-08-09', 6], 
    ['2012-08-10', 0], ['2012-08-11', 0], ['2012-08-12', 0], 
    ['2012-08-13', 0], ['2012-08-14', 0], ['2012-08-15', 0], 
    ['2012-08-16', 0], ['2012-08-17', 0], ['2012-08-18', 0], 
    ['2012-08-19', 0], ['2012-08-20', 0], ['2012-08-21', 0], 
    ['2012-08-22', 0], ['2012-08-23', 0], ['2012-08-24', 0], 
    ['2012-08-25', 0], ['2012-08-26', 0], ['2012-08-27', 0], 
    ['2012-08-28', 0], ['2012-08-29', 0], ['2012-08-30', 0], 
    ['2012-08-31', 0] 
]]; 
var plot = $.jqplot('chartdiv', timeline, { 
    title: 'Downloadstatistik', 
    axes: { 
     xaxis: { 
      renderer: $.jqplot.DateAxisRenderer, 
      tickOptions: { formatString: '%#d' }, 
      tickInterval: '1 day', 
      min: timeline[0][0][0], 
      max: timeline[0][timeline[0].length-1][0] 
     }, 
     yaxis: { 
      tickOptions: { formatString: '%.0f' }, 
      min: 0 
     } 
    } 
}); 

而且我覺得不需要墊。

編輯(新的jsfiddle加):

你可以在這裏測試此示例代碼:http://jsfiddle.net/JhHPz/4/

+0

那麼確定這個工程。但在底線(xaxis jqplot並沒有顯示所有天數爲1,3,6,9,而不是1,2,3,4,5,6 ......數據中的「點」被標記爲... – spotlr

+0

對不起,我當然錯過點擊時複製/粘貼jsFiddle鏈接。 我已經更新了我的答案一個新的。 另外,什麼意思當你說: ''從數據的「點」被標記''? – TwystO

+0

謝謝,現在效果很好;) – spotlr