js+css实现动态饼图效果代码
代码语言:html
所属分类:图表
代码描述:js+css实现动态饼图效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <style> *, *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } body { position: relative; margin: 0; background: #434a54; text-rendering: optimizeSpeed; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .row { display: block; width: 300px; margin: 50px auto; -webkit-animation: fadeIn .4s ease-in .4s both; animation: fadeIn .4s ease-in .4s both; } .row:before, .row:after { display: table; content: ' '; } .row:after { clear: both; } @media only screen and (min-width: 600px) { .row { width: 600px; } } .column { float: left; width: 300px; padding: 25px; } @-webkit-keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } } @keyframes fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } } /** * Donut Chart * -------------------------------------------------- */ .donut-chart { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; position: relative; overflow: hidden; width: 250px; height: 250px; border-radius: 50%; background-color: #f5f7fa; -webkit-box-shadow: 0 0 0 6px rgba(0, 0, 0, .2); box-shadow: 0 0 0 6px rgba(0, 0, 0, .2); } .outer-circle, .inner-circle { position: absolute; border-radius: 50%; } .outer-circle { top: 6%; right: 6%; bottom: 6%; left: 6%; background-color: #fff; -webkit-box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .2); box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .2); } .inner-circle { top: 22%; right: 22%; bottom: 22%; left: 22%; background-color: #f5f7fa; -webkit-box-shadow: 0 0 0 6px rgba(0, 0, 0, .2); box-shadow: 0 0 0 6px rgba(0, 0, 0, .2); } .inner-circle-label, .inner-circle-value { position: absolute; top: 50%; left: 0; display: block; width: 100%; text-align: center; } .inner-circle-label { font-size: 18px; line-height: 1; margin-top: -30px; color: #aab2bd; } .inner-circle-value { font-size: 42px; font-weight: bold; line-height: 1; margin-top: -12px; color: #656d78; } .wedge-container, .wedge, .wedge-extension, .wedge-label { position: absolute; top: 0; left: 0; width: 100%; height: 100%; -webkit-transition: all .4s linear; transition: all .4s linear; border-radius: 50%; } .wedge, .wedge-extension { -webkit-box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .2); box-shadow: inset 0 0 0 6px rgba(0, 0, 0, .2); } .wedge-value { font-size: 14px; font-weight: bold; line-height: 20px; position: absolute; top: 5%; left: 50%; display: block; width: 30px; margin-left: -15px; text-align: center; } .wedge-extension { z-index: 100; } .wedge { z-index: 200; } .wedge-label { z-index: 300; } </style> </head> <body> <section class="row"> <div class="column"> <div class="donut-chart" data-donut-chart="1"></div> </div> <div class="column"> <div class="donut-chart" data-donut-chart="2"></div> </div> </section> <script> ;(function(window, document, undefined) { 'use strict'; var DonutChart = DonutChart || { /** * Initialize Chart */ init: function(options) { this.settings(options); this.createChartStructre(); this.setChartMeta(); this.build(); }, // init() /** * Update Chart */ update: function(options) { this.settings(options); this.setChartMeta(); this.build(); }, // update() /** * Chart Settings */ settings: function(options) { this.config = { container: options.container ? options.container : this.config.container, data: options.data ? options.data : this.config.data, label: options.label ? this.label : 'Total', offset: options.offset ? options.offset : 0 }; }, // settings() /** * Build chart */ build: function() { var container = this.config.container.querySelector('.outer-circle'); var wedges = container.querySelectorAll('[data-wedge-id]'); var wedgesIdArray = []; for (var i = 0; i < wedges.length; i++) { wedgesIdArray.push(wedges[i].dataset.wedgeId); } for (var j = 0; j < this.config.data.wedges.length; j++) { if (wedgesIdArray.indexOf(this.config.data.wedges[j].id) == -1) { var wedge = this.createWedge(this.config.data.wedges[j]); container.appendChild(wedge); } this.setWedge(this.config.data.wedges[j]); } }, // createWedges() /** * Create chart structure */ createChartStructre: function() { var outer = document.createElement('div'); var inner = document.createElement('div'); var label = document.createElement('span'); var value = document.createElement('span'); outer.className = 'outer-circle'; inner.className = 'inner-circle'; label.className = 'inner-circle-label'; value.className = 'inner-circle-value'; this.config.container.appendChild(outer); this.config.container.appendChild(inner); inner.appendChild(label); inner.appendChild(value); }, // createChartStructre() /** * Set chart meta */ setChartMeta: function() { var label = this.config.container.querySelector('.inner-circle-label&.........完整代码请登录后点击上方下载按钮下载查看
网友评论0