Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Circle Chart</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!--based on code from https://codepen.io/maoberlehner/pen/jwVWQz-->
- <style>
- @media only screen and (min-width: 600px) {
- body {
- margin-right:200px;
- margin-left:200px;
- margin-top: 0;
- }
- }
- .flex{
- display: grid;
- grid-row-gap: 1rem;
- grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
- }
- .button {
- box-shadow:inset 0px 1px 0px 0px #54a3f7;
- background:linear-gradient(to bottom, #007dc1 5%, #0061a7 100%);
- background-color:#007dc1;
- border-radius:3px;
- border:1px solid #124d77;
- display:inline-block;
- cursor:pointer;
- color:#ffffff;
- font-family:Arial;
- font-size:13px;
- padding:6px 24px;
- text-decoration:none;
- text-shadow:0px 1px 0px #154682;
- }
- .button:hover {
- background:linear-gradient(to bottom, #0061a7 5%, #007dc1 100%);
- background-color:#0061a7;
- }
- .button:active {
- position:relative;
- top:1px;
- }
- .circle-chart__circle {
- animation: circle-chart-fill 2s reverse; /* 1 */
- transform: rotate(-90deg); /* 2, 3 */
- transform-origin: center; /* 4 */
- }
- .circle-chart__info {
- animation: circle-chart-appear 2s forwards;
- opacity: 0;
- transform: translateY(0.3em);
- }
- @keyframes circle-chart-fill {
- to { stroke-dasharray: 0 100; }
- }
- @keyframes circle-chart-appear {
- to {
- opacity: 1;
- transform: translateY(0);
- }
- }
- </style>
- </head>
- <body>
- <button class="button" onclick="go()">Lets Go</button>
- <div class="grid">
- <section>
- <h2>Positive chart value</h2>
- <svg class="circle-chart" viewbox="0 0 33.83098862 33.83098862" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
- <circle class="circle-chart__background" stroke="#efefef" stroke-width="2" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431" />
- <circle id="mychart" class="circle-chart__circle" stroke="#00acc1" stroke-width="2" stroke-dasharray="30,100" stroke-linecap="round" fill="none" cx="16.91549431" cy="16.91549431" r="15.91549431" />
- <g class="circle-chart__info">
- <text id="outputval" class="circle-chart__percent" x="16.91549431" y="15.5" alignment-baseline="central" text-anchor="middle" font-size="8">30%</text>
- <text class="circle-chart__subline" x="16.91549431" y="20.5" id="outputtext" alignment-baseline="central" text-anchor="middle" font-size="2">Yay 30% progress!</text>
- </g>
- </svg>
- </section>
- </div>
- </body>
- <script>
- var chart = document.getElementById("mychart");
- var outputval = document.getElementById("outputval");
- var outputtext = document.getElementById("outputtext");
- function go(){
- //chart.classList.remove("circle-chart__circle");
- var d = 1;
- for(var i=30;i <= 50;i++){
- task(i,d);
- d++;
- }
- }
- function task(i,d) {
- setTimeout(function() {
- chart.setAttribute("stroke-dasharray",`${i},100`);
- outputval.innerHTML = `${i}%`;
- outputtext.innerHTML = `Yay, ${i}% doing good`;
- }, 20 * d);
- }
- </script>
- </html>
Add Comment
Please, Sign In to add comment