Laravel 5.1 format date array for chart.js data -


apologies, can't upload controller code right i'm hoping can info can give you.

i'm using chart.js plot line graph of data. i'm passing values controller data points , date matches date point. date labels on x axis , data points on y axis.

in view i'm receiving following array controller:

["2015-06-01","2015-05-01","2015-04-01","2015-03-01","2015-02-01","2015-01-01"] 

which being encoded json. now, should attempting format date bit more readable inside controller or inside view?

edit

this piece of code that's sending weight data view:

$weight = weight::where(compact('user_id', 'gecko_id'))->orderby('weighed_date', 'desc')->take(7)->get()->reverse();

and then

return view('gecko.show')             ->with('gecko', $gecko)             ->with('dates', $weight->lists('weighed_date'))             ->with('amounts', $weight->lists('gecko_weight')); 

i format in chartjs if purely looking change part of presentation. if @ question see can format our labels data points using like.

scalelabel: function (valuepayload) {     return number(valuepayload.value).tofixed(2).replace('.',',') + '$'; } 

now in case maybe like

scalelabel: function (value) {     return moment(value).format("ddd, ha"); ; } 

to format date in nice way. making use of momentjs in case.

warning: above not tested i've never done chartjs in theory should work.


Comments