问题
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