MongoDB Developer
Atlas
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Atlaschevron-right

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

Sourabh BagrechaPublished Nov 11, 2022 • Updated Nov 11, 2022
ReactGraphQLAtlasJavaScript
Copy Link
facebook icontwitter iconlinkedin icon
random alt
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Data is useless, at least on its own.
It’s really difficult to understand the real meaning of raw data without extracting meaningful insights and information through proper visualizations.
In the previous 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 create an analytics dashboard to display those insights from our database in a React app.
Analytics Dashboard implemented in React using data fetched from Atlas GraphQL API

Creating visualizations in React with Google Charts

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:

Querying a GraphQL custom resolver

We’ll create 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 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.
Lines 28-43 are the most important part of the analytics page. It is the GraphQL query that we are using to fetch the data from the custom resolvers we created in the previous part of this blog series. Create a new file: ./src/pages/Analytics.page.js
Visualize the spent amount with a pie chart
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. Create a new file: ./src/components/ModeAnalytics.component.js
Visualize spent amount per category
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.

Copy Link
facebook icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

Create a REST API with Cloudflare Workers and MongoDB Atlas


Nov 15, 2022
Article

Keeping Your Costs Down with MongoDB Atlas Serverless Instances


Oct 17, 2022
Quickstart

Creating an API with the AWS API Gateway and the Atlas Data API


Aug 26, 2022
Tutorial

Build Your Own Function Retry Mechanism with Realm


Jul 19, 2022
Table of Contents