I found the following thread very useful
http://groups.google.com/group/jqplot-users/browse_thread/thread/1986...
I would like to get all the y axis values or ticks in an array...My intention is to count the number of digits in each of the ticks and find the most frequent number of digits. Based on that im planning to truncate number of digits in the y axis ticks/values. For example : if most of the ticks have 6 digits, truncate to 3 digits and append the word (in Thousands) to the axis label.
How can i achieve this? In the below function i can get the ticks one by one...but i need to get them in advance so that i can decide by what factor to truncate the number.Please ignore the function numberwithCommas.Its just an example.
(function($) {
$.jqplot.tickNumberFormatter = function (format, val) {
if (typeof val == 'number') {
if (!format) {
format = '%.1f';
}
return numberWithCommas($.jqplot.sprintf(format, val));
}
else {
return String(val);
}
};
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
}
@Boro : Thank you so much for the reply. Could you please let me know what this line does exactly?
var ticks = $('.jqplot-' + axisName + '-tick');
The same line isn't working in my code. How can I use it?
Can I use it to push all ticks into an array before the control enters the formatter? In other words, can I get all the ticks before the control enters the following function?
$.jqplot.tickNumberFormatter = function (format, val) {
The following code works brilliantly in your example. Why doesn't it work in mine :(
var axisName = 'yaxis';
var count = 0;
var ticks = $('.jqplot-' + axisName + '-tick');
for (count = 0; count <= ticks.length; count++)
{
console.log($(ticks[count]).text());
}