stal269 / ring-chart Goto Github PK
View Code? Open in Web Editor NEWSimple Ring Chart Angular Component From CSS, JS, HTML only
Home Page: https://shimital.github.io/ring-chart/
License: MIT License
Simple Ring Chart Angular Component From CSS, JS, HTML only
Home Page: https://shimital.github.io/ring-chart/
License: MIT License
When not passing "centerColor", then you might see display artefact between the sections of the ring-chart
you can simplify your current implementation, by removing the creation of sections as elements in the DOM.
(because then you need to actually style them, rotate them etc.)
you can use the css radial-gradient property (it even has very good browser support)
to style a single DOM element in the desired pie/ring
effect, by using multiple stops (of different sizes) on the same linear gradient.
a demo of how its done can be seen here: https://bennettfeely.com/csspiechart/
Sum of section percentages must be equal to 1
you should be able to draw a pie chart even if the sum of total sections is not equal to 1,
by normalizing the given percentages to 1.
example 1 (when the total sum is greater than 1):
[{"color": red, "percentage": 1}, {"color": blue, "percentage": 1}]
=> should resolve into 0.5 for each of the sections.
example 2 (when the sum is smaller than 1):
[{"color": red, "percentage": 0.5}, {"color": blue, "percentage": 0.25}]
=> should resolve into 0.66 for red, and 0.33 for blue.
the general way to do that calculation:
you can calculate the total sum of all percentages.
const allPercentages = sections.map(s => s.percentage).reduce((sum, i) => sum + i, 0);
and then recalculate the normalized percentage for each section to be: const normalizedPercentage = percentage / allPercentages
.
as a side-effect, you also gain the ability to pass the percentage as "whole numbers" like 50, 75 etc. (representing 50%
, 75%
).
because now they don't have a restriction that force then to sum to 1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.