gwatts / jquery.sparkline

A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser
http://omnipotent.net/jquery.sparkline/
1.24k stars 278 forks source link

Stacked bars uneven iff they do not all add to same total (bug with the rounding off of the bar heights) #93

Open katowulf opened 11 years ago

katowulf commented 11 years ago

A fiddle using the 2.1.2 release: http://jsfiddle.net/katowulf/Yk6WJ/

If they add to the same total, my bars look great:

image

But if I add a bar that exceeds the total, they render off by a pixel, giving the chart a bit of an erratic look (it's even more uneven when the bars are very small):

image

katowulf commented 11 years ago

Fwiw, I'd be happy to submit a fix for this if someone wants to give me a jumpstart by suggesting a likely offender.

gwatts commented 11 years ago

Not sure I understand what you expect to be displayed - In your example all your columns except the last have values that add up to 5, so they're all even.. The last adds up to 9 - Why would you not expect the final column to be larger than the others?

katowulf commented 11 years ago

It's not that the last column is taller. Have a closer look at the images and the description: When one column is taller, the sum 5 columns are no longer the same height--they are off by a pixel or two.

gwatts commented 11 years ago

ah ok.. yep, that's a bug with the rounding off of the bar heights

mcmanuss8 commented 10 years ago

I took a stab at this which seemed to solve the problem (as well as issues 99 and 98).

Here's the change: https://github.com/mcmanuss8/jquery.sparkline/commit/ea51eb0b041adeb78352ff7612981906310b9663#diff-25d902c24283ab8cfbac54dfa101ad31