2012-07-11 62 views
2

我試圖設置使用jqplot水平條形圖如下:jqplot單槓問題

var plot1 = $.jqplot('graph', [gData], { 
    seriesDefaults: { 
     renderer:$.jqplot.BarRenderer, 
     rendererOptions: { 
      barDirection: 'horizontal' 
     } 
    }, 
    axes: { 
     yaxis: { 
      renderer: $.jqplot.CategoryAxisRenderer, 
      ticks: gTicks 
     } 
    } 
}); 

此代碼工作正常豎線,如:

var plot1 = $.jqplot('graph', [gData], { 

    seriesDefaults: { 
     renderer:$.jqplot.BarRenderer 
    }, 
    axes: { 
     xaxis: { 
      renderer: $.jqplot.CategoryAxisRenderer, 
      ticks: gTicks 
     } 
    } 
}); 

但是,當我去使它水平,突然酒吧不再排隊蜱。例如,對於某些滴答,可能有兩個或更多個重疊的條。對於一些人來說,可能根本沒有。最後,還有一個'未定義'的勾號,似乎有很多條重疊。

gData和gTicks都是javascript數組。

有什麼想法?

編輯:未定義的類別實際上是我自己的創作,但問題保持不變。

回答

0

它不適用於您的原因是,我認爲,當您將圖形的方向更改爲水平時,不會相應地更改數據。因此,假定這就是問題所在,圖表的數據將必須是以下形式,as in the example at jqPlot's webpage

[[[2,1], [4,2], [6,3], [3,4]], 
    [[5,1], [1,2], [3,3], [4,4]], 
    [[4,1], [7,2], [1,3], [2,4]]] 

也可以使用一個值數組表示法(下),作爲相對上述(點的陣列)來表示一系列的:

[[200, 600, 700, 1000], 
    [460, -210, 690, 820], 
    [-260, -440, 320, 200]] 

這種表示法將允許你改變圖表的定向,而無需擔心的數據格式,如在下面的實施例,其中數據保持不變僅適當呈現圖表參數更改: