Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

I need help making a pie chart with pure css.

<!---I did a lot of research, but I still do not know to make a pie chart with pure css.
-->
<svg height="50" width="50" viewBox="0 0 50 50">
<style>


</style>
<circle cx="" cy="" r="23"/>
<circle cx="" cy="" r="23"/>
<circle cx="" cy="" r="23">
</svg>

1 Answer

Try this:

<!DOCTYPE html>
<html>
  <head>
    <title>Pie Chart</title>
  </head>
  <body>
    <style>
      .pie {
        width: 400px;
        height: 400px;
        background: conic-gradient(red 64%, blue 64% 84%, green 84% 94%, black 94%);
        border-radius: 50%;
      }
    </style>
    <div class="pie">
    </div>
    <div class="labels">
      <h2>Labels</h2>
      <p style="color:red;">Item 1: 64%</p>
      <p style="color:blue;">Item 2: 20%</p>
      <p style="color:green;">Item 3: 10%</p>
      <p>Item 4: 6%</p>
    </div>
  </body>
</html>

This seems to me to be the easiest way to do it.

Reference (scroll down to "Using CSS Conic Gradients for Pie Charts"): https://www.sitepoint.com/create-css-conic-gradients-pie-charts