flot dynamic bar width

时光总嘲笑我的痴心妄想 提交于 2019-12-25 07:04:06

问题


This is the code i used to use for bars

bars: {
                   show: true,
                   barWidth: 12 * 24 * 60 * 60 * 300,

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).

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 ?


回答1:


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...



来源:https://stackoverflow.com/questions/25365103/flot-dynamic-bar-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!