2015-12-17 49 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值。