2015-12-17 67 views
1

我想要有一個多個系列條形圖(使用orderBars)中間系列需要顯示變量抽樣的errorBars。我似乎無法得到酒吧在網格中正確對齊,我無法弄清楚如何使其工作。現在到我完成的地方,左邊的&右側橫杆已正確對齊,但中間橫杆向上跳起並未正確對齊。無法使用jQuery Flot orderBars和錯誤條對齊條形圖

Flot bars

這是我目前編碼:

$(function() { 
    var figure0 = [{ 
     label: "Cost 1", 
     data: [[1,5229.7], [2,4496.8], [3,4307.0], [4,4205.6], [5,3809.7]], 
     bars: { 
      order: 0 
     } 
    }, { 
     label: "Cost 2", 
     data: [[1,4973.5,500], [2,3380.4,100], [3,3105.7,100], [4,3000.8,100], [5,2939.0,100]], 
     points: { 
      radius: 0, 
      errorbars: "y", 
      yerr: { 
       show: true, 
       upperCap: "-", 
       lowerCap: "-", 
       radius: 5, 
       color: "black" 
      } 
     }, 
     bars: { 
      align: "center", 
      order: 1 
     } 
    }, { 
     label: "Cost 3", 
     data: [[1,1045.2], [2,881.8], [3,809.0], [4,850.8], [5,771.5]], 
     bars: { 
      order: 2 
     } 
    }]; 

    var formatFigure0 = { 
     series: { 
      stack: false, 
      bars: { 
       show: true, 
       fill: true, 
       barWidth: 0.2, 
       lineWidth: 1, 
       fillColor: { colors: [{ opacity: 1 }, { opacity: 1 }] } 
      } 
     }, 
     xaxis: { 
      show: true, 
      ticks: [1, 2, 3, 4, 5], 
      tickDecimals: 0, 
      tickSize: 1, 
      axisLabel: "Quintiles" 
     }, 
     yaxis: { 
      show: true, 
      tickDecimals: 0, 
      tickSize: 1000, 
      axisLabel: "Dollars (millions)" 
     }, 
     legend: { 
      show: true, 
      position: "ne", 
      margin: 10, 
     }, 
     grid: { 
      hoverable: false 
     } 
    }; 

    $.plot($("#figure0DIV"), figure0, formatFigure0); 
}); 
+0

你可以建立一個[小提琴](http://jsfiddle.net)? – Raidri

+0

我試圖建立一個,但無法使其工作。如果我最終得到其他問題,我會更多地考慮它。謝謝! –

回答

0

errorbarsorderBars插件真的不一起工作。你可以讓他們的工作,但只有很容易當er​​rorbars是中央的酒吧:

enter image description here

要做到這一點,我不得不作出一些改變你的代碼(見本fiddle):

  • 給所有三個槓相同的對齊(使用orderBars時,你可以逃脫指定沒有對齊的話)
  • 從每個數據點中刪除在第二個數據系列的第三值,因爲這被解釋爲偏移(跳)爲酒吧(也刪除錯誤在這裏或酒吧)
  • 添加了禁用錯誤(在這裏,你必須有每個數據點的三個值)與巴新的數據數據序列(這個「黑客」也被用在了example的海軍報頁)

更新後的代碼(取代原來的第二個數據系列):

}, { 
    label: "Cost 2", 
    data: [ 
    [1, 4973.5], [2, 3380.4], [3, 3105.7], [4, 3000.8], [5, 2939.0] 
    ], 
    bars: { 
    order: 1 
    } 
}, { 
    data: [ 
    [1, 4973.5, 500], [2, 3380.4, 100], [3, 3105.7, 100], [4, 3000.8, 100], [5, 2939.0, 100] 
    ], 
    points: { 
    radius: 0, 
    errorbars: "y", 
    yerr: { 
     show: true, 
     upperCap: "-", 
     lowerCap: "-", 
     radius: 5, 
     color: "black" 
    } 
    }, 
    bars: { 
    show: false 
    }, 
    lines: { 
    show: false 
    } 
}, 

PS:如果你想獲得這與errorbars所有的酒吧工作,那麼你必須計算x偏移量爲酒吧並相應地更改錯誤數據序列上的x值。