From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Preparing customers report using chart

Preparing customers report using chart

In this lecture, we will use the line chart to prepare the report of customers. Here we have already fetched the customer's data, but we have to modify the data and use it in the chart. We will do exactly the same thing which we have done for the sales chart. But here, we will just add count of the total customers accounts. So we will use the created at value of each user record and count the customers which are created on a particular date. To calculate the count and store it in an array of objects, we will use the reduce method. So in the dashboard actions.js file, we have already fetched the data of customers. I will just create a new variable and say const customersByDate is equal to customersData.reduce accumulator and will receive the customer as well. Now we will use the same logic as the salesByDate property. So I'll say const date, where we'll format the date and passing the customer.createdAt. Then the validation that if not ACC of date, then ACC of date is equal to date and…

Contents