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 sales report using chart

Preparing sales report using chart

In this lecture, we will use the line chart to prepare a report for sales. Here we have fetched the sales data already but we have to modify the data and use it in the chart. However, we have to pass the data to the chart as an array of objects where each object has two attributes. One is date and another is sales, which represents total sales on a particular date. So, we will use the grand total price and the SO date time attribute and calculate the total of grand total price in particular SO date time. Then I will store the calculated amount in the sales attribute and the SO date time in the date attribute of the object. To calculate the amount and store it in the desired array of objects, we will use the array.reduce method. So I will open the dashboard actions js file and here we have already fetched the data of sales. So I will create a new variable const salesByDate is equal to salesMasterData.reduce accumulator, sale. Now I will create a new key value pair in the object where…

Contents