EduardoDominguez / dwpe

Automatically exported from code.google.com/p/dwpe
MIT License
0 stars 0 forks source link

Y-axis labels don't show up properly when they're decimal values -- only the top-most value and zero appear #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Y-axis labels need to show incremental values when they're decimals (less
than 1, greater than zero)

Original issue reported on code.google.com by fg.mag...@gmail.com on 17 Mar 2010 at 3:13

GoogleCodeExporter commented 8 years ago
Any updates on this? This is the only hurdle preventing me from using it as I 
am rendering line charts with decimal values.

Original comment by dwaynech...@gmail.com on 23 Nov 2010 at 5:38

GoogleCodeExporter commented 8 years ago
Try this:
                topValue: function(){
                        var topValue = 0;
                        var allData = this.allData().join(',').split(',');
                        $(allData).each(function(){
                            if(parseFloat(this,10)>topValue) topValue = parseFloat(this);
                        });
                        var topValue = Math.ceil(topValue) + '';
                        return (Math.ceil(topValue/Math.pow(10,topValue.length-1)))*Math.pow(10,topValue.length-1);
                },

This line solves the decimal problem, by simply rounding the numbers: var 
topValue = Math.ceil(topValue)

The next line makes the y-axis go higher than the the bars. It rounds up to 10 
to the power of the number of digits in your highest value.  If you have 10 y 
axis lables, then they will be nice round numbers (with only or two significant 
figures). A simple way to have 10 y axis lables is by setting your graph height 
to 300px when you call it). 

Original comment by adri...@gmail.com on 11 Feb 2011 at 2:22