Implement Analytics Dashboard in React using Custom Resolvers for Atlas GraphQL API

A React.js tutorial explaining how to implement charts to show insights based on user data.

Sourabh Bagrecha
3 min readMay 24, 2022

Data is useless, at least on its own.
It is really difficult to understand the real meaning of raw data without extracting meaningful insights and information through proper visualizations.

In the last part of our blog series, we learned how to create custom resolvers for GraphQL that allow us to perform advanced analytics. In this part, we will learn how to implement an analytics dashboard to display those insights from our database in a React.js app using GraphQL.

Analytics Dashboard implement in React.js which is using data fetched from MongoDB Realm GraphQL
Analytics Dashboard implemented in React.js which is using data fetched from Atlas GraphQL API

Installing dependencies

To make our lives easier and instead of reinventing the wheel, we will use the React-Google-Charts library to create visualizations of the analytics data that we fetch from our Custom Resolvers for GraphQL. Run the following command to install:

npm i react-google-charts

Analytics Dashboard page

We are creating an Analytics Home Page where we can track all the modes and categories and see where and how we are spending money in a consolidated view. By default, we are fetching the last one month’s analytics but the user can customize it as per their needs by using the custom date picker placed on top of the Analytics page.

Line no. 28 to 43 is the most important part of the Analytics page, it is the GraphQL Query that we are using to fetch the data from the Custom Resolver for GraphQL we created in the last part of this blog series.

Create a new file: ./src/pages/Analytics.page.js

ModeAnalytics component

The Mode Analytics component is used to visualize the amount we are spending using different modes of payment. Each expense in our app will have a “mode” attribute in it like UPI, Credit Card, Cash, etc. are some examples. Create a new file: ./src/components/ModeAnalytics.component.js

CategoryAnalytics component

The Category Analytics component is used to visualize the amount of money we are spending on different categories. Each expense in our app will have a “category” attribute in it like Education, Travel, Entertainment, etc. Create a new file: ./src/components/CategoryAnalytics.component.js

Putting it all together in the App.js file

Now we will add our Analytics page in our Routes so that the user can navigate to the analytics from anywhere in the app.

Conclusion

That’s it. We have implemented a fully functional Analytics Dashboard in React. We were able to utilize the custom resolvers for Atlas GraphQL API we created for fetching and performing complex calculations that were beyond regular CRUD operations.

In the next part, we will see how we can utilize Website/Single-Page-Apps hosting provided by Atlas App Services Static Hosting to host our expengo app, which will make our app accessible from anywhere in the world.

If you have any doubts or concerns, please feel free to reach out to us on Community Forums. I have created a dedicated Forum Topic for this blog where we can discuss anything related to this Blog-series.

And before you ask, here’s the GitHub Repository(custom-resolvers branch) for this tutorial series.

--

--

Sourabh Bagrecha

Talks about GraphQL, JavaScript, MongoDB, Node.js, and React.js. Connect with me: linkedin.com/in/sourabhbagrecha | Postings on these blogs are my own