Nathan
Nathan

Reputation: 979

JqPlot: Set min/max on date axis

Need some advice around setting the maximum value on a DateAxisRenderer axis - I've tried pad, no luck. Assuming I want the xaxis maximum to be one day greater than my last date, how would I set this?

       xaxis:{ max:'??', tickInterval: '86400000', renderer:$.jqplot.DateAxisRenderer, tickOptions:{ formatString:'%b %#d' }}

Upvotes: 1

Views: 7082

Answers (2)

Junior Grão
Junior Grão

Reputation: 1

if you need to define min and max from yaxis, you can do this: [enter link description here][1]

HTML

<div id="chart" style="height:500px"></div>

Scripts

$(document).ready(function(){ 

var line1=[['1', 0.0],['2', 8.3],['3', 10.1],['4', 10.0],['5', 8.3],['6', 8.3],['7', 20.8],['8', 23.8],['9', 27.1],['10', 23.8],['11', 22.3],['12', 24.4]];

var plot1 = $.jqplot('chart', [line1], {
title:'Default Date Axis',
axes:{
    xaxis:{
        renderer: $.jqplot.DateAxisRenderer,
        tickOptions:{formatString:'%b'},
    },
    yaxis:{
        //renderer:$.jqplot.DateAxisRenderer,
        tickOptions:{formatString: '%.1f %'},
        min:0,
        max:100,
        tickInterval:'10'
    }
}, 
 series:[{color:'#5FAB78'}], 
 highlighter: { 
     show: false, 
     sizeAdjust: 1 
 }, 
 cursor: { 
     show: false 
 },
 seriesDefaults: {  
      showMarker:true, 
      pointLabels: { show:true }  
 } 
 });
}); 

Upvotes: 0

AnthonyLeGovic
AnthonyLeGovic

Reputation: 2335

You can get the biggest x-value of your serie using :

var biggest_day = plot2.axes.xaxis._dataBounds.max.

Adding 1 day to this value is done by

biggest_day += 86400000 (time in millisecond).

You can then apply this new bound to your plot doing

plot1.axes.xaxis.max = biggest_day

Finally, don't forget to replot : plot1.replot()

Upvotes: 2

Related Questions