flot动态条宽
这是我以前用于酒吧的代码
bars: { show: true, barWidth: 12 * 24 * 60 * 60 * 300,
当x轴的min
和max
分别为2014-2-2.gettime()
和2014-9-9
时,该宽度适用于我(我试图给你的想法不是确切的语法)。
但是当数据从6月到7月时,条形似乎很宽
有没有办法让flot本身制作宽度并使其不会太大而不能太小?
据我所知, flot
不会自动缩放条形图。 默认的barWidth: 1, // in units of the x axis
为barWidth: 1, // in units of the x axis
,当然不会为大规模时间图切割它。 所以这是我尝试一种简单的算法,它在条形图之间留下相同大小的条形和空白区域:
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)); }
未经测试的代码……