简体   繁体   中英

Group by Week using Angular, Underscore and Moment js

Need some help please. I am trying to group my click stats by week using underscore and moment.

here is the code:

var groupedByWeekFbCompleted = _.groupBy($scope.facebookObjects, function(item) {
    return moment(item.timeclicked,"YYYY-MM-DD").isoWeek();
});

here is a screen shot of the chart it gives me 在此输入图像描述

When I print groupedByWeekFbCompleted to the console this is what I get 在此输入图像描述

The data comes from the DB formatted like this

2016-06-18 14:03:56

I can not figure out what 24, 26, 27, 28 and 29 represent. My hope is to display the first day of the week as a label and then group by that week

If you will take that date string and parse it using moment you will get something like

moment("2016-11-08 14:03:56", "YYYY-MM-DD HH:mm:ss").isoWeek()
// 45

24, 26, 27, 28 and 29 are the week day, and the values are arrays of dates within that week

EDIT

To display a date string on your labels, you can use the .format method to parse the timestamp you get from the moment function, provide it the same format you used, like so:

moment("2016-11-08 14:03:56", "YYYY-MM-DD HH:mm:ss").format("YYYY-MM-DD HH:mm:ss") 
// output: "2016-11-08 14:03:56"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM