score:1
Accepted answer
You can make a special function to do this sorting by using Array.map()
and Array.filter()
methods:
const categories = [
"2021-08-04",
"2021-08-05",
"2021-08-06",
"2021-08-07",
"2021-08-08",
"2021-08-09",
"2021-08-10",
"2021-08-11",
"2021-08-12",
"2021-08-13",
"2021-08-14",
"2021-08-15",
"2021-08-16",
"2021-08-17",
"2021-08-18",
"2021-08-19",
"2021-08-20",
"2021-08-21",
"2021-08-22",
"2021-08-23",
"2021-08-24",
"2021-08-25",
"2021-08-26",
"2021-08-27",
"2021-08-28",
"2021-08-29",
"2021-08-30",
"2021-08-31",
"2021-09-01",
"2021-09-02",
"2021-09-03",
"2021-09-04",
"2021-09-05",
"2021-09-06",
"2021-09-07",
"2021-09-08",
"2021-09-09",
"2021-09-10",
"2021-09-11",
"2021-09-12",
"2021-09-13",
"2021-09-14",
"2021-09-15",
"2021-09-16",
"2021-09-17",
"2021-09-18",
"2021-09-19",
"2021-09-20",
"2021-09-21",
"2021-09-22",
"2021-09-23",
"2021-09-24",
"2021-09-25",
"2021-09-26",
"2021-09-27",
"2021-09-28",
"2021-09-29",
"2021-09-30",
"2021-10-01",
"2021-10-02",
"2021-10-03",
"2021-10-04",
"2021-10-05",
"2021-10-06",
"2021-10-07",
"2021-10-08",
"2021-10-09",
"2021-10-10",
"2021-10-11",
"2021-10-12"]
const messagesSent = [ 32,
60,
71,
3,
1,
25,
16,
23,
28,
25,
2,
1,
43,
49,
32,
35,
26,
2,
1,
8,
36,
47,
15,
20,
2,
1,
2,
18,
20,
30,
43,
4,
4,
15,
14,
48,
39,
3,
2,
0,
48,
34,
15,
9,
1,
3,
1,
85,
27,
72,
11,
4,
2,
0,
29,
13,
21,
15,
32,
2,
0,
58,
37,
37,
24,
5,
1,
0,
0,
0]
const messagesReceived = [29,
79,
80,
7,
2,
24,
32,
23,
44,
42,
3,
1,
65,
69,
46,
47,
23,
3,
1,
28,
35,
65,
22,
19,
4,
1,
7,
10,
32,
31,
13,
8,
2,
4,
48,
53,
46,
7,
4,
0,
48,
40,
23,
18,
2,
6,
2,
79,
25,
86,
9,
8,
5,
0,
25,
18,
18,
14,
37,
2,
0,
52,
70,
27,
25,
17,
1,
0,
0,
0]
const organizeData = (days, sent, received) => {
const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
// get name of weekday
const getDayOfWeek = date => {
const dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : dayNames[dayOfWeek];
}
return dayNames.map((dayName) => {
let correspondingMessagesSent = []
let correspondingMessagesReceived = []
const matchedDays = days.filter((day, index) => {
if(dayName === getDayOfWeek(day)) {
correspondingMessagesSent.push(sent[index])
correspondingMessagesReceived.push(received[index])
return day
}
})
return { [dayName]: { dates: matchedDays,
sent: correspondingMessagesSent,
received: correspondingMessagesReceived} }
})
}
console.log(organizeData(categories, messagesSent, messagesReceived))
/* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */
.as-console-wrapper { max-height: 100% !important; top: 0; }
Source: stackoverflow.com
Related Query
- Group data by weekdays in Highchart
- HighChart - Group data by day
- Group Highchart time data into weeks and months
- Highchart group by month from corresponding column data
- How to render Gantt Highchart from data source
- Highchart columnrange, color code lines based on data
- how to hide highchart x - axis data values
- Reduce gap between series data in Bar Highchart
- creating highchart with ajax json data
- Plot Highchart Gauge with JSON Data
- HighChart Heatmap with JSON data
- How to display highchart y axis with constistant data
- Adding new data to highchart tooltip
- Highchart (Column Chart) : Few data labels are not appearing for a series
- Can color of data label be different inside and outside of the bar in Highchart
- Highchart data series filled with different colors
- Is it possible update Highchart data automatically and make animated effect?
- time data with irregular intervals in HighChart
- Highcharts - Global configuration with common code and unique data & Headings
- Columns HighChart remove spacing for empty data series
- Django - can't get highchart to display data
- Creating a Highchart for every data set
- Group series names in columns in highchart horizontal legend
- Showing multiple data with same x and y in highchart
- How to fill data dynamically in Highchart
- Data with timestamp group to month(like Jan, Feb, March) and showing as total count for month in Highcharts
- Several Series with the same xAxis data in HighChart
- Export chart image data locally in HIghchart
- Use MySQL data as the chart data for the cakephp highchart plugin
- I cant save my highchart chart data in localStorage
More Query from same tag
- How add Angular Highcharts to my angular project?
- Highcharts, have all but first series turned off on chart load
- heroku does not load jquery on https
- Highcharts - gap between series in stacked area chart
- HighCharts Orgcharts make scroll able container
- Config gauge series highchart
- How to hide color axis in heatmaps using highcharts
- Javascript - convert HTML div with SVG to image
- Multiple pie-charts in the same chart with HighCharts
- Highcharts data series label. for each data point
- highchart bargraph rectangles remove stroke
- highcharts inside ng-repeat (AngularJS)
- Set up a highchart export server without Java
- Not able to resize doughnut chart build with angular js
- Highcharts - My nice thin cross hair changes to a thick green cross hair when adding categories
- TypeError: Highcharts[h] is not a function
- Meteor Highcharts using collection data
- Highcharts yaxis labels not working
- highchart : create stock chart
- gem Lazy High Charts - Pie Donut
- ng2-highcharts chart update after load
- How to bind model list variable to highchart
- How to use Highcharts Gantt chart in angular?
- Area spline chart using Highchart
- Highcharts plotline with label in the left of the line
- Add Data text on top of Bars (vertical) - Highcharts Bar charts
- Set datetime format in x-axis of Highchart
- Highcharts - spider web chart questions
- Highcharts (highstock.js) exporting function does not work on Embedded Visualforce pages
- Highcharts: change legend symbol runtime