Creating a personalized circular progress bar using React

I am looking to replicate this specific design using React and React Native

[![enter image description here][1]][1]

After attempting to implement it with the React Circle Progressbar package from here, I have not been successful in achieving the desired outcome. Can anyone offer assistance with this?

I am willing to share my complete component for further insight into the current status

function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
  var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;

  return {
    x: centerX + radius * Math.cos(angleInRadians),
    y: centerY + radius * Math.sin(angleInRadians),
  };
}

function describeArc(x, y, radius, startAngle, endAngle) {
  var start = polarToCartesian(x, y, radius, endAngle);
  var end = polarToCartesian(x, y, radius, startAngle);

  var largeArcFlag = endAngle - startAngle <= 180 ? '0' : '1';

  var d = [
    'M',
    start.x,
    start.y,
    'A',
    radius,
    radius,
    0,
    largeArcFlag,
    0,
    end.x,
    end.y,
  ].join(' ');

  return d;
}

Answer №1

Using simple SVG code, you can achieve a similar effect to this. The gradient may not be perfect, but it's quite close. You can adjust the length of the "progress" using the stroke-dasharray property.

<svg viewBox="0 0 200 210" width="200">
  <defs>
    <mask id="m1">
      <circle cx="100" cy="105" r="55" fill="white"/>
    </mask>
    <linearGradient id="lg1" gradientTransform="rotate(0) skewX(-20) skewY(-40)">
      <stop offset="0"  stop-color="red" />
      <stop offset="75%" stop-color="orange" />
    </linearGradient>
  </defs>
  <image mask="url(#m1)" href="https://i.sstatic.net/ptG0J.png" width="200" />
  <path pathLength="360" d="M100 175 a 75 75 0 1 1 1 0"
    stroke="LightSlateGray" fill="none" stroke-width="30"
    stroke-linecap ="round" stroke-dasharray="270 360"
    stroke-dashoffset="-45"/>
  <path pathLength="360" d="M100 175 a 75 75 0 1 1 1 0"
    stroke="url(#lg1)" fill="none" stroke-width="15"
    stroke-linecap ="round" stroke-dasharray="180 360"
    stroke-dashoffset="-45"/>
  <g transform="translate(100 180)" font-size="16" font-family="sans-serif" font-weight="bold" text-anchor="middle">
    <text>Overall</text>
    <text transform="translate(0 20)">Wellbeing</text>
  </g>
</svg>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The concept of localStorage is not recognized in the next.js framework

Currently working with next.js for frontend development. Facing an issue where I need to access user data from localStorage, but due to next.js being a server-side rendering framework, I am unable to retrieve data from localStorage. How can I solve this pr ...

The validation for the number input step in HTML does not function properly when using the value property

Currently working on a form that requires users to input numbers with up to two decimal points, such as valid money amounts. Utilizing Next.js (React) as the JavaScript framework for this project. Encountered an issue where entering a number with more tha ...

changing tooltip color in bootstrap based on the parent element

Is there a way to adjust the bootstrap tooltip background-color based on the container? For example, my header has a white background and my footer is black. #header .tooltip-inner{ background-color:fade(@grayWhite,80); } #footer .tooltip-inner{ backgro ...

ReactJS buttons update their color when clicked

Utilizing Material UI Buttons in ReactJS, I currently have 3 buttons within my project. <> <Button variant="contained">Button 1</Button> <Button variant="contained">Button 2</Button> <Button variant="contained">Button3& ...

Minimize the number of HTTP requests by including CSS and JS files in PHP

I've been considering a method to reduce the number of HTTP requests made when loading a page by minimizing the amount of downloaded files, while still keeping separate files on the server. The thought process is as follows: <!DOCTYPE html> &l ...

How can I make my slider perfectly accommodate the component inside?

I am working on developing a slider similar to the McDonald's one: The main goal for my slider is to adjust to the container element size, so that when the user clicks the left or right buttons, the slider smoothly moves to the corresponding directio ...

Clarification: Obtain the state prior to the current one

I've been diving into the React Documentation and came across a topic that I'm struggling to grasp fully: https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state function Counter() { const [count, setCount] = useState(0) ...

What steps are involved in implementing Local fonts in theme UI for Next JS?

I am currently developing an application using next JS with [theme-UI][1]. However, I need to implement local or custom fonts in my project and I'm unsure of how to do this. Below is the current theming setup: const theme = { fonts: { ...

How can I embed HTML elements into a Three.js rendered 3D image?

Using React framework, I am working with a 3D image in glb/gltf format and rendering it with three.js packages. My goal is to assign a unique number to each object and display it above them. In my approach, I attempted to access the canvas element and add ...

Automatically adjusting input box size and position in real-time

I am working on a form that includes a button and an input field. When the user clicks on the button "ADD MORE FIELDS," I want to dynamically generate a new input box. Although I have tried using code from this jsfiddle link and it works, my goal is to ach ...

What is the best approach to implement pagination in the UI-Bootstrap Typeahead Directive?

In my current Angular Project, I am utilizing the UI-Bootstrap's Typeahead Directive for a specific purpose. However, I am encountering an issue when dealing with a large amount of similar data using this directive. It seems that displaying only the ...

What is the best way to display an overlay internal link on top of the current one after it has been clicked

I am looking to create a button that, when clicked, will slide in a different page link and modify the URL to cover 80% of the website, while keeping the previous page in the background. Upon closing, the URL will revert back to the original one. I have c ...

Is there a way to monitor network requests (for debugging purposes) in React Native specifically on a Windows platform?

I've come across several solutions about viewing network requests in React Native on Mac OS, but I need help with debugging on Windows. Can anyone guide me on how to achieve this? ...

Scrolling container embedded within a parent with absolute positioning

I have encountered a tricky situation with an absolute positioned div and its nested div having overflowing content. My goal is to enable vertical scrolling for the child div, however, my attempts so far have been unsuccessful. The challenge here is that I ...

Modify the input class once an image has been chosen (But not yet submitted)

Looking for a solution to update background image when file is selected <input type="file" class="imgupload" name="file" /> I've created image uploader with a hidden form element inside a padded div, displaying a background image. Want to chan ...

Utilize a function inside the useContext hook in React/Next

I have successfully moved the Firebase auth to a useContext component. However, I am currently facing a challenge in referencing the async GoogleLogin function from the useContext to the button's onClick event on the Login page. Here is my UserContex ...

What are some effective strategies for reducing excessive re-rendering of React components?

Here is how I am displaying a list of components on the screen: const MessagesContainer = ({ messages, categories, addHandler }) => { const options = categories.map(category => ( { value: category.name, label: category.name } )); ...

Errors occur when Axios fails to send the correct response [React]

I've been encountering an issue while handling error responses from Axios in React. When I attempt to log the error, it shows as Network error and error.response is undefined. The request involves a simple POST with the Authorization header correctly ...

Ensure that a bootstrap table's cell occupies the entire available space, while also allowing for scrolling when there is overflow

Many questions have been raised about Bootstrap, Tables, and responsiveness. However, I have yet to find one that addresses my specific issue with getting a particular cell (<td> element) to: (a) Fill the available space, stopping at the window boun ...

Retrieving data from a URL and iterating through it to add to the state array of a ReactJS component

Recently, I have been diving into learning ReactJS and have faced some challenges in dealing with a component's state. When fetching a URL that returns a JSON file, I aim to set the state of my component based on the values from this file. While it&ap ...