2013-03-15 31 views
0

我有以下代碼以從JSON/AJAX請求繪製數據jqplot墊不工作

function plotit(data){ 
     $.jqplot.config.enablePlugins = true; 
     $("#jqplot-chart1").empty(); 
      plot1 = $.jqplot('jqplot-chart1', data,{ 
       axesDefaults: { pad: 1.2}, 
       title: 'data', 
       animate: true, 
       animateReplot: true, 
       axes: { 
        xaxis: { 
          label: "---", 
          tickOptions: {formatString: '%d-%m-%Y'}, // ex 02-09-2002,23:09:55 - %d 
          renderer: $.jqplot.DateAxisRenderer 
         }, 
         yaxis: { 
          label: "Y " 
         } 
       }, 
       cursor:{ 
        zoom: true, 
        showTooltip : true, 
        constrainZoomTo : 'x', 
        showVerticalLine : true 
       } 
      } 
    ); 
    } 

這是JSON響應數據的例子:

[[["2013-03-02 00:00:00","2"],["2013-03-01 00:00:00","72"],["2013-02-28 00:00:00","26"],["2013-02-27 00:00:00","67"],["2013-02-26 00:00:00","48"],["2013-02-25 00:00:00","50"]]] 

但是當我情節基本上我有兩個問題: - 首先是情節的頂部和最大值之間的填充是巨大的,我想動態調整劇情的高度(圖片中的紅色箭頭) 第二個是右邊的最後一個值被附加到bord上呃的情節(圖片中的藍色箭頭) ![Plot結果] [1]

任何人都可以幫助我嗎?

這是形象,解釋這個問題:

http://img7.imageshack.us/img7/963/sanstitrebtt.png

回答

2

你可以使用渲染後您的dataBounds值:

var minY = plot2.axes.yaxis._dataBounds.min; 
var maxY = plot2.axes.yaxis._dataBounds.max; 

(你可以得到其minX和maxX的同樣使用x軸。 )

然後,您可以要求jqplot使用此邊界來繪製精確範圍:

plot2.axes.yaxis.min = minY; 
plot2.axes.yaxis.max = maxY; 

(同樣爲xaxis行事);

最後,重新繪製你的圖:plot2.replot();

您最終的圖形,根據您的數據值有一定的限度。

PS:你可以在numberTicks以及使用plot2.yaxis._numberTicks或plot2.yaxis.numberTicks工作(不知道哪一個是有效的)

見類似的帖子here