I am converting a flash graph to a js NVD3 ( D3 ) based line graph, but am having difficulty with the order of the x-axis.
I would like the x-axis data to display as ( current month counting back 12mths):
Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec, Jan
but the chart library is placing Jan to the front and then draws a line from Dec on the right side to jan on the left.
I have the following code:
<script>
nv.addGraph(function() {
var months = ["Jan","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"];
var thisYear = [], lastYear = []
thisYear.push( {x: 2, y: 101034} );
thisYear.push( {x: 3, y: 229948} );
thisYear.push( {x: 4, y: 278940} );
thisYear.push( {x: 5, y: 370409} );
thisYear.push( {x: 6, y: 254532} );
thisYear.push( {x: 7, y: 201229} );
thisYear.push( {x: 8, y: 221323} );
thisYear.push( {x: 9, y: 210640} );
thisYear.push( {x: 10, y: 174958} );
thisYear.push( {x: 11, y: 172434} );
thisYear.push( {x: 12, y: 13527} );
lastYear.push( {x: 1, y: 0} );
lastYear.push( {x: 2, y: 380996} );
lastYear.push( {x: 3, y: 214687} );
lastYear.push( {x: 4, y: 123827} );
lastYear.push( {x: 5, y: 171242} );
lastYear.push( {x: 6, y: 155463} );
lastYear.push( {x: 7, y: 163326} );
lastYear.push( {x: 8, y: 209324} );
lastYear.push( {x: 9, y: 165603} );
lastYear.push( {x: 10, y: 147929} );
lastYear.push( {x: 11, y: 154803} );
lastYear.push( {x: 12, y: 85055} );
lastYear.push( {x: 1, y: 9005} );
var myData = [
{
values: thisYear,
key: 'This Year',
color: '#ff7f0e'
},
{
values: lastYear,
key: 'Last Year',
color: '#2ca02c'
}
];
var chart = nv.models.lineChart()
.margin({left: 100})
.useInteractiveGuideline(true)
.showLegend(true)
.showYAxis(true)
.showXAxis(true);
chart.xAxis
.axisLabel('Month of Year')
.tickValues([1,2,3,4,5,6,7,8,9,10,11,12])
.tickFormat(function(d){
return months[d]
});
chart.yAxis //Chart y-axis settings
.axisLabel('$ ex GST Turnover');
d3.select('#chart svg') //Select the <svg> element you want to render the chart in.
.datum(myData) //Populate the <svg> element with chart data...
.call(chart); //Finally, render the chart!
//Update the chart when window resizes.
nv.utils.windowResize(function() { chart.update() });
return chart;
});
</script>
And it renders a graph that looks like this:

This is an example of the old flash graph:
So my question is: How do I move "Jan" to the right side as per the order in the array?
Thanks for your time and aid. PS. ( if anyone is wondering all the array pushes is dynamic from server side code )
:)
