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 Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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
Loading ..................

Console