MongoDB Developer
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right

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

Sourabh BagrechaPublished Nov 11, 2022 • Updated Nov 11, 2022
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
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/
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.


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.

Facebook Icontwitter iconlinkedin icon
Rate this tutorial

Adding Autocomplete To Your NextJS Applications With Atlas Search

Feb 28, 2023

Best Practices and a Tutorial for Using Google Cloud Functions with MongoDB Atlas

Jun 13, 2023

How to Manage Data at Scale With MongoDB Atlas Online Archive

Sep 23, 2022

MongoDB Charts Embedding SDK with React

Jan 26, 2023
Table of Contents