Eliminating aliasing from an SVG circular element

I am currently working on creating an animated SVG pie chart. The setup involves two SVG elements, where the first element is given a border-radius of 50%, and the second element is a circle that is filled up to a specific value. This results in one circle appearing above another circle, both having identical dimensions.

However, there seems to be some sort of SVG aliasing issue that is proving difficult to eliminate. This aliasing is quite noticeable on the top, left, bottom, and right "corners" of the circle, particularly when viewed on Google Chrome.

Below is the snippet of the HTML code:

<figure id="pie" data-percentage="60">
  <div class="receiver"></div>
  <svg width="200" height="200" class="chart" shape-rendering="geometricPrecision">
    <circle r="50" cx="100" cy="100" class="pie" shape-rendering="geometricPrecision"/>
  </svg>
</figure>

You can also refer to my codepen link for a more detailed insight into the problem. I have explored several solutions, including utilizing the shape-rendering attribute in SVG, but unfortunately, the issue persists.

Additionally, here is a screenshot showcasing the aliasing problem, although it may not be as pronounced as displayed in the codepen (at least from my perspective):

https://i.sstatic.net/iX9Aw.png

Answer №1

Creating a Smooth SVG Percentage Circle

In the past, I faced a similar issue detailed here: Resolution for Pixelated Circle Edge. This problem arises when adjusting an element with border-radius.
Instead of opting for the solution provided in the linked answer, consider using/modifying only SVG for both better performance and visual appeal.

See below for an example:

var circ = document.getElementsByClassName("pie2");
var text = document.getElementsByClassName("text");
text = text[0];
circ = circ[0];
var maxvalue = 320;
var value = maxvalue;
var stop = false;

function increase() {
  if (value > 0) {
    circ.style.strokeDashoffset = value--;
    text.textContent = Math.abs(Math.floor((value / maxvalue) * 100) - 100) + "%";
  } else {
    clearInterval(intervalid);
  }
}

var intervalid = setInterval(increase, 25);
.pie {
  fill: none;
  stroke: #222;
  stroke-width: 99;
}
.pie2 {
  fill: none;
  stroke: orange;
  stroke-width: 100;
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
}
.text {
  font-family: Arial;
  font-weight: bold;
  font-size: 2em;
}
<figure id="pie" data-percentage="90">
  <svg width="200" height="200" class="chart" shape-rendering="geometricPrecision">
    <circle r="50" cx="100" cy="100" class="pie" shape-rendering="geometricPrecision" />
    <circle r="50" cx="100" cy="100" class="pie2" />
    <text class="text" x="80" y="110">0%</text>
  </svg>
</figure>

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 issue persists where the state value fails to update even after receiving a new value from a child component

I'm facing some difficulties with this particular issue. I designed a modal (SetLevel) to allow the user to choose a level and then update my initial state called 'level'. I pass my prop in handleChange within the SetLevel component like so ...

Having trouble launching the SpeechRecognition feature on Ionic Cordova for Macdonst?

TL; DR: The app wasn't working because I was using it on Android 6.0 and needed to manually grant microphone access permission. Here's the story: I set out to develop an Ionic app that utilizes speech recognition with this plugin: https://githu ...

What is the best approach to establish multiple global prefixes in a NestJS project?

I am looking to define multiple Global Prefixes for my application such as: admin/products admin/users admin/... api/products api/search api/... shop/products shop/cart shop/... In the main.ts file, I can set a single global prefix using th ...

The issue of `window.scrollTo(0, 240)` not functioning properly when used in combination with

I am currently in the process of developing a website using Reactjs and Gatsby. The issue I'm facing is that when I have window.scrollTo(0, 240) within the componentDidMount() function, everything works fine when I refresh the site. However, when I n ...

Using Angular 6 to import GeoJSON into a Leaflet map

I am facing an issue while trying to import a GeoJson file into Leaflet in my Angular app version 6. Although the geojson is being successfully drawn on the leafletmap, I am encountering an error that is preventing me from building my app. Is there anyone ...

Retrieving arrays in subdocuments with MongoDB queries

Being a novice in the realm of mongodb, I welcome any corrections if my terminology is incorrect: The document snippet below showcases some information: { "_id" : ObjectId("524b0a1a7294ec8a39d4230f"), "name" : "Irbesartan", "decompositions" ...

Implementing TypeScript with styled components using the 'as' prop

I am in the process of developing a design system, and I have created a Button component using React and styled-components. To ensure consistency, I want all my Link components to match the style and receive the same props as the Button. I am leveraging t ...

What could be the reason for the 'tsc' command not functioning in the Git Bash terminal but working perfectly in the command prompt?

I recently installed TypeScript globally on my machine, but I am facing an issue while trying to use it in the git bash terminal. Whenever I run tsc -v, I encounter the following error: C:\Users\itupe\AppData\Roaming\npm/node: l ...

Having difficulty extracting the values of td elements from a table in HTML string using PHP's XPath parser

From a Wikipedia page, I have the html snippet below... <table class="wikitable"> <tbody> <tr> <td>mod_access</td> <td>Versions older than 2.1</td> <td>Included by Default</td> </tr ...

Issue with React occurring when attempting to delete an input component

I seem to be facing a challenge that I can't quite figure out whether it's related to React or not. To help illustrate the issue, I've created a simple example outside of my project: https://codepen.io/as3script/pen/VMbNdz?editors=1111 Wit ...

Is it possible to implement a feature in Angular and Bootstrap where the toggle menu can be closed by clicking anywhere on the page, rather than just the toggle button

I'm working on an Angular project where I've implemented a navbar component. The navbar is responsive and includes a toggle button that appears when the browser window is resized. This button allows users to hide or display the menus. One issue ...

Comparing form submission with a button click to pass data using Ajax - success in one method but failure in the other

I am facing an issue with two pieces of jquery code in my Flask application. While one works perfectly, the other is not functioning as expected. Both the form and a button trigger the same function through ajax calls. Currently, for troubleshooting purpos ...

No data being fetched by Ajax

So, I'm facing an issue with my code that is supposed to locate a user in the 'users' table and display it in an alert. However, the error log shows "Function is not set" and the alert also reflects this. Here's the HTML form snippet: ...

Angular Material List Component with Material Table

In this code snippet, everything seems to be functioning perfectly. When you click on the magnifying glass icon, some additional information is displayed: <mat-card *ngIf="(bills && bills.length > 0) && all" style="overflow-x: auto;" ...

Customizing Background Color in React Bootstrap Table Based on Value

Having a little issue that's causing me some trouble. I have a React Bootstrap Table displaying data from an API, and I'm looking to enhance it by changing the row color to green if a specific value is greater than zero. Here is an example: const ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...

How to use jQuery to style tables with borders

I'm just getting started with jQuery and I attempted the following: <input value="1" type="checkbox" name="mytable" id="checkbox2" style="float:left;" /> {literal} <script src="http://code.jquery.com/jquery-latest.js"></script> < ...

The 'SVGResize' or 'onresize' property is not available on the 'SVGProps<SVGSVGElement>' type

Using React with SVG I'm facing an issue with handling the resizing event of an svg element. I have looked into using the SVGResize and onresize events, but encountered compilation errors when trying to implement them: const msg1 = (e: any) => co ...

Is there anyone who can provide a comprehensive explanation for what is going on here?

{ // Let's figure out how to launch my HTML file as a webpage in Chrome. "version": "0.2.0", "configurations": [ { "type": "pwa-chrome", &q ...

Comparing locale strings in Javascript using the valueOf method of the String prototype

I have the following code snippet: class MyClass { constructor(name) { this.name = name; } toString() { return this.name; } valueOf() { return this.name; } } const list = [new MyClass("b"), new MyClass("ä")]; list.sort(); ...