I managed to solve my problem using ideas from the Mehasse post.
Determining the max value proposed by Mehasse did not remove unnecessary tick lines, but helped me find the answer.
By default, in the / jqplot mounts, a 4 y-axis axis line is required. Thus, if the maximum value is lower than 4 , then when they round, duplication will be displayed on the y-axis label ( formatString: '%d' ).
Basically I want the tick interval to be either Max(y) \ 4 when Max(y) > 4 , or 1 otherwise:
function actionPlanExtender() { var series_max =maxSeries(this.cfg.data); var numberOfTicks =4; var tickInterval = Math.max(1, Math.ceil(series_max/numberOfTicks)); this.cfg.axes = { xaxis : { renderer : $.jqplot.DateAxisRenderer, rendererOptions : { tickRenderer:$.jqplot.CanvasAxisTickRenderer }, tickOptions : { fontSize:'10pt', fontFamily:'Tahoma', angle:-40, formatString:'%b-%y' }, tickInterval:'2592000000' }, yaxis : { min: 0, rendererOptions : { tickRenderer:$.jqplot.CanvasAxisTickRenderer, }, tickOptions: { fontSize:'10pt', fontFamily:'Tahoma', angle:0, formatString: '%d', }, tickInterval: tickInterval }, }; this.cfg.axes.xaxis.ticks = this.cfg.categories; }
To calculate the y-max value, I get the graph value using this.cfg.data , which has the form [series_1,..., series_n] with series_i = [[x_1, y_1],..., [x_m, y_m]]
The maxSeries function looks like this:
function maxSeries(datas) { var maxY = null; var dataLength = datas.length; for ( var dataIdx = 0; dataIdx < dataLength; dataIdx++) { var data = datas[dataIdx]; var l = data.length; for ( var pointIdx = 0; pointIdx < l; pointIdx++) { var point = data[pointIdx]; var y = point[1]; if (maxY == null || maxY < y) { maxY = y; } } } return maxY; }
Please note that in my case I know my business, I have no value below 0 . This code should be updated if it is not.