浮条动态条宽度 [英] flot dynamic bar width
问题描述
这是我用于酒吧的代码
bars: {
show: true,
barWidth: 12 * 24 * 60 * 60 * 300,
当x轴的min
和max
值分别为2014-2-2.gettime()
和2014-9-9
时,宽度与我一起工作(我想给您的想法不是确切的语法).
that width works with me when the min
and max
value of x axis is 2014-2-2.gettime()
and 2014-9-9
respectively (i am trying to give you the idea not the exact syntax).
但是当数据从6月到7月时,条形似乎很宽
but the bar seems to wide when the data is from june to july
有没有一种方法可以使浮点数本身变宽并使它既不太大又不太小?
is there a way to make flot itself make the width and make it not too large and not too small ?
推荐答案
据我所知,flot
不会自动缩放条形图.当然,默认的barWidth: 1, // in units of the x axis
不会针对大型时间图进行裁剪.因此,这是我尝试的一种简单算法,该算法将等大小的小节和小节之间留有空白:
To my knowledge, flot
won't auto-scale the bars. The default barWidth: 1, // in units of the x axis
, of course, isn't going to cut it for large-scale time plots. So here's my attempt for a simple algorithm which leaves equal sized bars and white space in between bars:
calcBarWidth = function(numBars, minTime, maxTime){
// assuming an even distribution
var totWidth = maxTime - minTime;
// totalWidth = (numBars * barSize) + ((1 + numBars) * barSize), solved for barSize
return (totWidth / ((2 * numBars) + 1));
}
未经测试的代码...
Untested code...
这篇关于浮条动态条宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!