cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!--

Change the data-percentage attribute on `div.pie-chart` to render a fresh pie chart

-->

<div class="pie-chart" data-percentage="33">
  <svg viewBox="-100 -100 200 200">
		<path d="" />
  </svg>
</div>

<h3></h3>
            
          
!
            
              .pie-chart {
    display: block;
    max-width: 80px;
    max-height: 80px;
    width: 100%;
    padding: 0;
	  margin: 20px auto 0;
    transform-origin: 50% 50%;
    -moz-transform-origin: 40px 40px;
    -ms-transform: rotate(-90deg);
    transform: rotate(-90deg);
}

.pie-chart ~ h3 {
	text-align: center;
	font-family: 'Helvetica', sans-serif;
	font-size: 24px;
	font-weight: normal;
	color: gray;
}

.pie-chart svg {
    max-height: 80px;
    border-radius: 50%;
    border: 1px solid #eee;
    background: #ffffff;
}

.pie-chart svg path {
    fill: #0074a2;
    -moz-transform: translate3d(0, 0, -1px);
}
            
          
!
            
              draw_pie_chart();
window.onresize = draw_pie_chart();

function draw_pie_chart() {
    var percentage, // percentage for the data attribute
        path, // path for svg
        angle, // 1% = 3.6deg; used for coord mapping
        radius = 50, // radius of the pie chart in pixels
        coords = []; // holds Cartesian plane coords for svg path

    percentage = parseInt( document.querySelectorAll( '.pie-chart[data-percentage]' )[0].getAttribute( 'data-percentage' ) );
  
    angle = percentage * 3.6; // 1% ~ 3.6deg
    radius = radius * 2;      // get diameter

    coords[0] = radius * Math.cos( Math.PI * angle / 180 );
    coords[1] = radius * Math.sin( Math.PI * angle / 180 );

    path = 'M0,0 L' + radius + ',0 A' + radius + ',' + radius + ' 0 1,1 ' + coords[0] + ',' + coords[1] + ' Z';

    document.querySelectorAll( '.pie-chart svg path' )[0].setAttribute( 'd', path );
    
    document.querySelectorAll( 'h3' )[0].innerHTML = percentage + '%';

}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console