How to Create and Responsive Dynamic Donut Maps with TailwindCSS – Smashing Magazine
CSS is amazing – I’m often amazed at how far it’s come in the years I’ve been using it (~2005 – present). One such surprise came when I noticed this tweet Shruti Balasa which demonstrated how to create a pie chart using conic-gradient().
It is quite simple. Here is a code snippet:
div { background: conic-gradient(red 36deg, orange 36deg 170deg, yellow 170deg); border-radius: 50%; }
Using this small amount of CSS, you can create gradients that start and stop at specific angles and define a color for each ‘segment’ of the pie chart.
Happy Days!
Brills, I thought I could use this instead of a map library for a data dashboard project I’m working on for the new CockroachDB Cloud API, but I had a problem. I didn’t know the values for my chart beforehand, and the values I received from the API were not in degrees!
Here’s a preview link and open source repos of how I worked around those two problems, and in the rest of this post I’ll explain how it all works.
Dynamic data values
Here is some sample data from a typical API response I sorted by value.
const data = [ { name: 'Cluster 1', value: 210, }, { name: 'Cluster 2', value: 30, }, { name: 'Cluster 3', value: 180, }, { name: 'Cluster...
source: https://news.oneseocompany.com/2023/03/07/how-to-create-and-responsive-dynamic-donut-maps-with-tailwindcss-smashing-magazine_2023030741586.html
Your content is great. However, if any of the content contained herein violates any rights of yours, including those of copyright, please contact us immediately by e-mail at media[@]kissrpr.com.