国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript實現動態統計圖開發實例

2019-11-20 11:12:52
字體:
來源:轉載
供稿:網友

本文實例講述了javascript實現動態統計圖的代碼。分享給大家供大家參考。具體如下:
運行效果截圖如下:

具體代碼如下
html代碼:

<div id="content">    <div class="legend">    <h1>汽車銷量:</h1>    <div class="skills">    <ul>    <li class="jq">大眾</li>    <li class="css">豐田</li>    <li class="html">別克</li>    <li class="php">福特</li>    <li class="sql">長安</li>    </ul>    </div>    </div>    <div id="diagram"></div>    </div>    <div class="get">    <div class="arc">    <span class="text">大眾</span>    <input type="hidden" class="percent" value="95" />    <input type="hidden" class="color" value="#97BE0D" />    </div>    <div class="arc">    <span class="text">豐田</span>    <input type="hidden" class="percent" value="90" />    <input type="hidden" class="color" value="#D84F5F" />    </div>    <div class="arc">    <span class="text">別克</span>    <input type="hidden" class="percent" value="80" />    <input type="hidden" class="color" value="#88B8E6" />    </div>    <div class="arc">    <span class="text">福特</span>    <input type="hidden" class="percent" value="53" />    <input type="hidden" class="color" value="#BEDBE9" />    </div>    <div class="arc">    <span class="text">長安</span>    <input type="hidden" class="percent" value="45" />    <input type="hidden" class="color" value="#EDEBEE" />    </div>    </div>

css代碼:

#content {position:absolute;top:50%;left:50%;margin:-340px 0 0 -450px;width:900px;height:600px;}.legend {float:left;width:250px;margin-top:140px;}#content h1 {font-family:'Cabin Sketch', arial, serif;text-shadow:3px 3px 0 #ddd;color:#193340;font-size:40px;margin-bottom:40px;text-align:right;}.skills {float:left;clear:both;width:100%;}.skills ul,.skills li {display:block;list-style:none;margin:0;padding:0;}.skills li {float:right;clear:both;padding:0 15px;height:35px;line-height:35px;color:#fff;margin-bottom:1px;font-size:18px;}

js代碼:

var o = {      init: function () {        this.diagram();      },      random: function (l, u) {        return Math.floor((Math.random() * (u - l + 1)) + l);      },      diagram: function () {        var r = Raphael('diagram', 600, 600),          rad = 73;        r.circle(300, 300, 85).attr({ stroke: 'none', fill: '#193340' });        var title = r.text(300, 300, 'loading...').attr({          font: '20px Arial',          fill: '#fff'        }).toFront();        r.customAttributes.arc = function (value, color, rad) {          var v = 3.6 * value,            alpha = v == 360 ? 359.99 : v,            random = o.random(91, 240),            a = (random - alpha) * Math.PI / 180,            b = random * Math.PI / 180,            sx = 300 + rad * Math.cos(b),            sy = 300 - rad * Math.sin(b),            x = 300 + rad * Math.cos(a),            y = 300 - rad * Math.sin(a),            path = [['M', sx, sy], ['A', rad, rad, 0, +(alpha > 180), 1, x, y]];          return { path: path, stroke: color }        }        $('.get').find('.arc').each(function (i) {          var t = $(this),            color = t.find('.color').val(),            value = t.find('.percent').val(),            text = t.find('.text').text();          rad += 30;          var z = r.path().attr({ arc: [value, color, rad], 'stroke-width': 26 });          z.mouseover(function () {            this.animate({ 'stroke-width': 50, opacity: .75 }, 1000, 'elastic');            if (Raphael.type != 'VML') //solves IE problem    this.toFront();            title.animate({ opacity: 0 }, 500, '>', function () {              this.attr({ text: text + '/n' + value + '%' }).animate({ opacity: 1 }, 500, '<');            });          }).mouseout(function () {            this.animate({ 'stroke-width': 26, opacity: 1 }, 1000, 'elastic');          });        });      }    }    $(function () { o.init(); });

希望本文所述對大家學習javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安乡县| 永和县| 丁青县| 长寿区| 宣威市| 晋中市| 商河县| 曲靖市| 浮山县| 渭源县| 樟树市| 鄱阳县| 常山县| 五原县| 隆安县| 惠安县| 宁蒗| 阿克陶县| 聂荣县| 铜山县| 赫章县| 福贡县| 棋牌| 舒城县| 玉山县| 大安市| 垦利县| 靖西县| 大荔县| 长沙县| 卢氏县| 盐城市| 虹口区| 蒙山县| 永定县| 白银市| 呼伦贝尔市| 惠东县| 曲水县| 峡江县| 五莲县|