Bar width problem in flot

Jernej Jerin picture Jernej Jerin · Jan 23, 2011 · Viewed 12.5k times · Source

I have a chart, that displays bars which represent rainfall in 24h. Now the first problem I had, was the default 1px width for bars in flot, see this example:

alt text

I searched for a solution and found that specifing barwidth like this:

bars: { 
        show: true,
        barWidth : 60*60*1000 //1h
    }

solves the problem. Now that actually works, but with one bad result. On my example (chart that displays 24 rainfall discretly every one hour) now this happens:

alt text

As you can see from first example, where bars are 1px width, the time goes from 13:00 previous day to 13:00 next day. Now when bar width are fixed, the time goes from 13:00 to 14:00 for some reason. Now I have tried diffrent barWidth setting, for example 50*60*1000, but that does not scale right plus the margin starts to appear beetwen each bars.

Now I would like to know how to fix this issue, that the timeline would go as in first example and the bars would have 1 hour width?

Answer

Jernej Jerin picture Jernej Jerin · Jan 24, 2011

The problem was in filling data with php to flot graphs. I overlooked the wrong suming of data and then had a condition, which added to php array the time. So at the end it added extra 1 hour. So the barWidth : 60*60*1000 in my case was the right thing to go.