简体   繁体   English

多条浮动图表-条形图距离太远

[英]flot multibar chart — bars too far away

I'm having an issue with flot multibar chart (using orderBars plugin) -- the bars are too far from each other, when having many (=24) columns. 我在float多栏图表(使用orderBars插件)时遇到问题-当有许多(= 24)列时,这些栏彼此之间相距太远。 I started up from this example, directly from http://en.benjaminbuffet.com/labs/flot/ 我是从http://en.benjaminbuffet.com/labs/flot/直接从此示例开始的

<script type='text/javascript' src='jquery.flot.min.js'></script>
<script type='text/javascript' src='jquery.flot.orderBars.js'></script>

... ...

var d1 = [];
for (var i = 0; i <= 5; i += 1)
    d1.push([i, parseInt(Math.random() * 30)]);

var d2 = [];
for (var i = 0; i <= 5; i += 1)
    d2.push([i, parseInt(Math.random() * 30)]);

ds.push({
    data:d1,
    bars: {
        show: true, 
        barWidth: 0.3, 
        order: 1,
        lineWidth : 2
    }
});
ds.push({
    data:d2,
    bars: {
        show: true, 
        barWidth: 0.3, 
        order: 2
    }
});

$.plot($("#placeholder"), ds, {
    grid:{
        hoverable:true
    }
});

The bars are nicely next to each other, pairs separated by a space. 这些条很好地彼此相邻,两行之间用空格隔开。

But, if I put there 24 columns (yes, I want to create chart for values on 24 hours), ie change the beginning of the code: 但是,如果我在此处放置24列(是的,我想在24小时内为值创建图表),即更改代码的开头:

var d1 = [];
for (var i = 0; i <= 23; i += 1)
    d1.push([i, parseInt(Math.random() * 30)]);

var d2 = [];
for (var i = 0; i <= 23; i += 1)
    d2.push([i, parseInt(Math.random() * 30)]);

There is a space between the bars that belong to the one x-value; 属于一个x值的小节之间有一个空格; and no space between the two pairs. 两对之间没有空格。 This is very confusing, user is mismatching the pairs. 这很令人困惑,用户对不匹配。 I need no space (or very little space) between the corresponding bars, and reasonable space between the pairs. 我在对应的小节之间不需要空格(或很小的空格),而在两对之间则不需要合理的空格。

Here is a picture of both graphs, so you can see the problem: 这是两个图形的图片,因此您可以看到问题:

在此处输入图片说明

Any help on this? 有什么帮助吗? Thx. 谢谢。

You have 24 bars in a confined space. 您在狭窄的空间中有24条。 You want more space between the groups of bars. 您希望条形组之间有更多空间。 Your options are: 您的选择是:

1.) you increase width of your plot. 1.)增加图的宽度。

2.) you decrease the size of each bar. 2.)减小每个栏的大小。

You can't adjust the space between the bars directly. 您不能直接调整条形之间的间距。 From the comments to the plugin: 从评论到插件:

The plugin adjust the point by adding a value depanding of the barwidth
 * Exemple for 3 series (barwidth : 0.1) :
 *
 *          first bar décalage : -0.15
 *          second bar décalage : -0.05
 *          third bar décalage : 0.05

Here's some code snips with possible fixes: 以下是一些可能的修复程序的代码片段:

 var d1 = []; for (var i = 0; i <= 23; i += 1) d1.push([i, parseInt(Math.random() * 30)]); var d2 = []; for (var i = 0; i <= 23; i += 1) d2.push([i, parseInt(Math.random() * 30)]); ds = []; ds.push({ data: d1, bars: { show: true, barWidth: 0.3, order: 1, lineWidth: 2 } }); ds.push({ data: d2, bars: { show: true, barWidth: 0.3, order: 2 } }); $.plot($("#placeholder"), ds, { grid: { hoverable: true } }); ds1 = []; ds1.push({ data: d1, bars: { show: true, barWidth: 0.005, order: 1, lineWidth: 2 } }); ds1.push({ data: d2, bars: { show: true, barWidth: 0.005, order: 2 } }); $.plot($("#placeholder1"), ds1, { grid: { hoverable: true } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://www.flotcharts.org/flot/jquery.flot.js"></script> <script src="http://rawgit.com/emmerich/flot-orderBars/master/js/jquery.flot.orderBars.js"></script> <div id="placeholder" style="width:3000px; height:300px"></div> <div id="placeholder1" style="width:600px; height:300px"></div> 

EDITS - UPDATED ANSWER 编辑-更新的答案

Another idea if you could drop the plugin and jitter the values yourself. 如果您可以删除插件并自己抖动值,则另一个想法。 This would allow better control on the spacing. 这样可以更好地控制间距。

See this snip: 看到以下片段:

 var barWidth = 0.2; var jitterVal = barWidth / 1.5; var d1 = []; for (var i = 0; i <= 23; i += 1) d1.push([i - jitterVal, parseInt(Math.random() * 30)]); var d2 = []; for (var i = 0; i <= 23; i += 1) d2.push([i + jitterVal, parseInt(Math.random() * 30)]); ds = []; ds.push({ data: d1, bars: { show: true, barWidth: barWidth } }); ds.push({ data: d2, bars: { show: true, barWidth: barWidth } }); $.plot($("#placeholder"), ds, { grid: { hoverable: true } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://www.flotcharts.org/flot/jquery.flot.js"></script> <div id="placeholder" style="width:400px; height:300px"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM