gsap实现扇形饼状图图表交互效果代码

代码语言:html

所属分类:图表

代码描述:gsap实现扇形饼状图图表交互效果代码

代码标签: gsap 扇形 图表 交互 饼状图

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">

<style>
    @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap');

html, body {
  font-family:'Roboto', sans-serif;
  width:100%;
  height:100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background:#000;
  color:#fff;
  overflow:hidden;
}

svg {
  width:100%;
  height:100%;
  max-width:800px;
  max-height:800px; 
  font-size:36px;
}

ul {
  width:95px;
}

li {
  padding-bottom:15px;
}
</style>

</head>
<body>
<!-- partial:index.partial.html -->
<ul>
  <li data-val="160">Water: 160</li>
  <li data-val="75">Milk: 75</li>
  <li data-val="55">Juice: 55</li>
  <li data-val="48">Beer: 48</li>
  <li data-val="31">Wine: 31</li>
  <li data-val="16">Soda: 16</li>
</ul>

<svg viewBox="0 0 400 400">
  <g id="pieChart">
    <circle id="center" cx="200" cy="200" r="50" fill="#10101a" stroke="#000" stroke-width="8" />
  </g>
  <text id="nTxt" x="200" y="213" text-anchor="middle"></text>
</svg>
<!-- partial -->
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/DrawSVGPlugin3.min.js"></script>
    <script>
    var colors = ["f94144","f9844a","f9c74f","43aa8b","4d908e","577590","277da1"]

function makeChart(){  
  var i,
      arr = [],
      lis = document.getElementsByTagName("li")      

  for (i=0; i<lis.length; i++) arr.push( gsap.getProperty(lis[i], 'data-val') )
  
  var sum = arr.reduce((a,b)=>a+b),
      currentPercent = 0

  for (i=0; i<arr.length; i++){
    currentPercent += arr[i]/sum*100
    
    var dur = 3-1.5*i/arr.length,
        ez = 'power3',
        c = document.createElementNS("http://www.w3..........完整代码请登录后点击上方下载按钮下载查看

网友评论0