angularjs - NVD3 Date values are not correct -


i'm trying use nvd3 display charts in angular app. receive date in format of 2015-12-01t00:00:00. when try format display on x-axis receive jan 1, 1970 gmt offset. below chart options. value passed in tickformat come or doing wrong.

vm.options = {     chart: {         type: 'historicalbarchart',         height: 450,         margin : {             top: 20,             right: 20,             bottom: 65,             left: 50         },         x: function (d) {             return new date(d.date).gettime();         },         y: function(d) {             return d.data;         },         showvalues: true,         valueformat: function(d){             return d3.format(',.1f')(d);         },         duration: 100,         xaxis: {             axislabel: 'x axis',             tickformat: function(d) {                 return d3.time.format('%b %y')(new date(d));             },             rotatelabels: 30,             showmaxmin: false         },         yaxis: {             axislabel: 'y axis',             axislabeldistance: -10,             tickformat: function(d){                 return d3.format(',.1f')(d);             }         },         tooltip: {             keyformatter: function(d) {                 return d3.time.format('%x')(new date(d));             }         },         zoom: {             enabled: true,             scaleextent: [1, 10],             usefixeddomain: false,             usenicescale: false,             horizontaloff: false,             verticaloff: true,             unzoomeventtype: 'dblclick.zoom'         }     } }; 

my data looks following.

[     {         data: 4.3722         date: "2015-01-01t00:00:00"     },     {         data: 5.111         date: "2015-02-01t00:00:00"     },     {         data: 4.5758         date: "2015-03-01t00:00:00"     },     {         data: 4.9875         date: "2015-04-01t00:00:00"     } ] 

additional information seems there not setting when data returned angular service. if hard code data in vm.data, chart looks fine when switch receiving data service dates dec 69. below call service , data object.

vm.averagezone = []; var request = new requestobject(); shipmentservice.getbasicchartdata(request)     .then(function(result) {         vm.averagezone = result.data;         //vm.data = [         //    {         //        "key": "average",         //        "bar": true,         //        "values": vm.averagezone         //    }         //];     });  vm.data = [     {         "key" : "average" ,         "bar": true,         "values" : vm.averagezone     }];  

is there missing regarding data , how should set when returned service?

solution below ended working. removed vm.data below this.

vm.averagezone = []; var request = new requestobject(); shipmentservice.getbasicchartdata(request)     .then(function(result) {         vm.averagezone = result.data;         vm.data = [             {                 "key": "average",                 "bar": true,                 "values": vm.averagezone             }         ];     }); 

you don't need include xscale : d3.time.scale().

your x value returning numerical value: new date(d.date).gettime();, whereas d3.time.scale() function expects javascript date object.

this plot should work fine linear scale, representing time data milliseconds since 1 january 1970 00:00:00 utc. conversion date format happens in tickformat function.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -