Building a Performance Dashboard with React and Circular Progress Components
In this blog, we'll explore how to build a performance metrics dashboard using React. The dashboard displays circular progress indicators for different performance metrics like Accessibility, SEO, and Best Practices. The progress indicators fill up gradually, simulating a loading animation.
The project makes use of Tailwind CSS for styling, and several components are composed to create a flexible and reusable interface.
Project Overview
We'll create two main components:
CircularProgress – Displays a circular progress bar for a given percentage.
Dashboard – Shows multiple progress bars for different metrics, such as performance, accessibility, and more.
CircularProgress Component
The CircularProgress component handles the circular progress bar, which animates to the specified percentage. The component takes the following props:
innerCircleColor: The background color inside the circular progress.
percentage: The percentage of completion.
progressColor: The color of the progress bar.
bgColor: The background color outside the progress area.
textColor: The color of the percentage text.
title: The title of the metric.
Code Implementation
import React, { useEffect, useRef, useState } from 'react'; interface CircularProgressProps { innerCircleColor: string; percentage: number; progressColor: string; bgColor: string; textColor: string; title: string; } const CircularProgress: React.FC<circularprogressprops> = ({ innerCircleColor, percentage, progressColor, bgColor, textColor, title, }) => { const [currentPercentage, setCurrentPercentage] = useState(0); const innerCircleRef = useRef<htmldivelement null>(null); useEffect(() => { const speed = 50; // Speed of the animation const increment = () => { setCurrentPercentage((prev) => { if (prev >= percentage) return percentage; return prev + 1; }); }; const interval = setInterval(increment, speed); return () => clearInterval(interval); }, [percentage]); return ( <div classname="flex flex-col justify-center gap-2"> <div classname="relative flex items-center justify-center w-12 h-12 rounded-full" style="{{" background:> <div classname="absolute w-[calc(100%_-_6px)] h-[calc(100%_-_6px)] rounded-full" style="{{" backgroundcolor: innercirclecolor ref="{innerCircleRef}"></div> <p classname="relative text-[16px] font-semibold" style="{{" color: textcolor> {currentPercentage}% </p> </div> <p classname="text-[10px] font-semibold text-center">{title}</p> </div> ); }; export default CircularProgress; </htmldivelement></circularprogressprops>
Dashboard Component
The Dashboard component displays multiple instances of the CircularProgress component, each representing a different performance metric.
Code Implementation
import React from 'react'; import CircularProgress from './CircularProgress'; const Dashboard: React.FC = () => { return ( <div classname="bg-white flex flex-col items-center border h-auto w-full xl:px-[14rem] lg:px-[5rem] sm:px-0 py-[5rem] justify-center"> <div classname="w-full border rounded"> <div classname="py-12 border-b"> {/* Performance Metrics */} <div classname="flex flex-wrap justify-center gap-14 items-center"> <circularprogress innercirclecolor="Bisque" percentage="{99}" progresscolor="DarkOrange" bgcolor="Bisque" textcolor="DarkOrange" title="Performance"></circularprogress> <circularprogress innercirclecolor="Bisque" percentage="{96}" progresscolor="DarkOrange" bgcolor="Bisque" textcolor="DarkOrange" title="Accessibility"></circularprogress> <circularprogress innercirclecolor="lightgreen" percentage="{90}" progresscolor="LimeGreen" bgcolor="lightgreen" textcolor="LimeGreen" title="Best Practices"></circularprogress> <circularprogress innercirclecolor="Bisque" percentage="{100}" progresscolor="DarkOrange" bgcolor="Bisque" textcolor="DarkOrange" title="SEO"></circularprogress> </div> </div> </div> </div> ); }; export default Dashboard;
Home Component
In addition to the progress bars, the dashboard also includes a collapsible section that shows more detailed information about server response times.
Code Implementation
import React, { useState } from 'react'; import { IoIosArrowDown, IoIosArrowUp } from 'react-icons/io'; const Home: React.FC = () => { const [isExpanded, setIsExpanded] = useState(false); const handleToggle = () => { setIsExpanded(!isExpanded); }; return ( <div classname="rounded-md w-full mb-4" id="server-response-time"> <div classname="flex flex-col border w-full justify-between items-center text-sm text-red-600"> <div classname="flex items-center p-3 justify-between w-full"> <span classname="ml-2 text-gray-800"> <span classname="text-red-700">⚠️</span> Reduce initial server response time <span classname="text-red-500">— Root document took 820 ms</span> </span> <span classname="text-gray-800 cursor-pointer" onclick="{handleToggle}"> {isExpanded ? <ioiosarrowup></ioiosarrowup> : <ioiosarrowdown></ioiosarrowdown>} </span> </div> {isExpanded && ( <div classname="bg-white border-t border-t-blue-600"> <div classname="py-8 pl-12 pr-4"> <p classname="text-[13px] text-gray-700"> Learn more about server response time and performance optimizations.{' '} <a classname="text-blue-500 underline" href="#" target="_blank" rel="noopener noreferrer"> Read more. </a> </p> </div> </div> )} </div> </div> ); }; export default Home;
Conclusion
This performance dashboard showcases how to create reusable, animated circular progress components in React. By structuring the dashboard this way, you can easily expand it to track other performance metrics or integrate it into a broader application, making it a powerful tool for visualizing key metrics.
Feel free to adapt this code for your projects, and enjoy creating performance dashboards with React!
The above is the detailed content of how to make dynamic Progress bar in React.js. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
