Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="demo">
  <p>ドーナツグラフ</p>
<ul class="demo_list">
    <li>
    <div class="graph_box">
  <div class="graph_box_wrap white">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="15"></canvas>
    <div class="graph_box_percent"><span></span>%</div>  
  </div>
</div>
  </li>
  <li>
    <div class="graph_box">
  <div class="graph_box_wrap white">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="40"></canvas>
    <div class="graph_box_percent"><span></span>%</div>  
  </div>
</div>
  </li>
    <li>
    <div class="graph_box">
  <div class="graph_box_wrap white">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="56"></canvas>
    <div class="graph_box_percent"><span></span>%</div>  
  </div>
</div>
  </li>
      <li>
    <div class="graph_box">
  <div class="graph_box_wrap white">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="87"></canvas>
    <div class="graph_box_percent"><span></span>%</div>  
  </div>
</div>
  </li>
        <li>
    <div class="graph_box">
  <div class="graph_box_wrap white">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="100"></canvas>
    <div class="graph_box_percent"><span></span>%</div>  
  </div>
</div>
  </li>
</ul>
</div>
<div class="demo">
  <p>円グラフ</p>
<ul class="demo_list">
    <li>
    <div class="graph_box">
  <div class="graph_box_wrap">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="15"></canvas>
    <div class="graph_box_percent block"><span></span>%</div>  
  </div>
</div>
  </li>
  <li>
    <div class="graph_box">
  <div class="graph_box_wrap">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="40"></canvas>
    <div class="graph_box_percent block"><span></span>%</div>  
  </div>
</div>
  </li>
    <li>
    <div class="graph_box">
  <div class="graph_box_wrap">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="56"></canvas>
    <div class="graph_box_percent block"><span></span>%</div>  
  </div>
</div>
  </li>
      <li>
    <div class="graph_box">
  <div class="graph_box_wrap">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="87"></canvas>
    <div class="graph_box_percent block"><span></span>%</div>  
  </div>
</div>
  </li>
        <li>
    <div class="graph_box">
  <div class="graph_box_wrap">
    <canvas width="100" height="100" id="" class="match_graph" data-percent="100"></canvas>
    <div class="graph_box_percent block"><span></span>%</div>  
  </div>
</div>
  </li>
</ul>
</div>

              
            
!

CSS

              
                html{
  font-size:62.5%;
  color:#333;
}
p{
  font-size:1.6rem;
}
.demo_list{
  list-style-type:none;
  margin:0;
  padding:0;
  >li{
    display:inline-block;
    margin:0 20px;
  }
}
//graph_box
.graph_box{
  padding:5px;
  box-sizing: border-box;
}
.graph_box_wrap{
  position: relative;
  width: 100px;
  height: 100px;
  margin:0 auto;
  &.white{
      &:after{
      content:"";
      position:absolute;
      display: block;
      width: 70px;
      height: 70px;
      background:#fff;
      top:0;
      left:0;
      bottom:0;
      right:0;
      margin:auto;
      border-radius: 50% 50%;
    }
  }
}
.graph_box_percent{
  position: absolute;
  display: inline-block;
  width: 100%;
  top: 50%;
  left:0;
  text-align: center;
  font-size: 1rem;
  font-weight: bold;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  z-index: 1;
  &.block{
    display:block;
    position:static;
    margin-top:20px;
  }
  span{
    font-size: 2rem;
    font-weight: bold;
  }
}
              
            
!

JS

              
                  var cleate_graph = function(name,percent){
    var element = document.getElementById(name) ;
    var context = element.getContext( "2d" ) ;

    context.beginPath () ;

    var angleA = 360 * ( percent / 100 ) ;
    var angleB = 360 * ( (100 - percent) / 100 ) ;

    context.beginPath () ;
    context.arc( 50, 50, 50, (0 - 90) * Math.PI / 180, (angleA - 90) * Math.PI / 180, false ) ;
    context.lineTo( 50, 50 ) ;
    context.fillStyle = "#16a4b4" ;
    context.fill() ;

    context.beginPath () ;
    context.arc( 50, 50, 50, (angleA - 90) * Math.PI / 180, ((angleA + angleB) - 90) * Math.PI / 180, false ) ;
    context.lineTo( 50, 50 ) ;
    context.fillStyle = "#EBEBEB" ;
    context.fill() ;
  };

  var match_graph = document.getElementsByClassName('match_graph');
  for (var i = 0; i < match_graph.length; i++) {
    match_graph[i].setAttribute('id', 'graph_'+i);
    var name = match_graph[i].getAttribute('id');
    var percent = match_graph[i].getAttribute('data-percent');
    var percent_num =  match_graph[i].nextElementSibling.getElementsByTagName('span');
    percent_num[0].textContent = percent;
    cleate_graph(name,percent);
  }

              
            
!
999px

Console