前端开发

 首页 > 前端开发 > javascript > javascript实现动态统计图开发教程

javascript实现动态统计图开发教程

分享到:
【字体:
导读:
          javascript实现动态统计图开发教程 本文实例讲述了javascript实现动态统计图的代码。分享给大家供大家参考。具体如下: 运行效果截图如下: 具体代码如下 html代码: divid=contentdivclass=...

javascript实现动态统计图开发教程

本文实例讲述了javascript实现动态统计图的代码。分享给大家供大家参考。具体如下:
运行效果截图如下:

具体代码如下
html代码:


    
    

汽车销量:

         
        大众     丰田     别克     福特     长安     
    
    
    
    
              大众                         丰田                         别克                         福特                         长安                    

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如何实现索引图片切换效果
javascript如何实现索引图片切换效果 本文实例讲述了js实现索引图片切换效果的代码。分享给大家供大家参考。具体如下:运行效果截图如下: 具体代码如下 html代码:                css代码: .ft-prev, .ft-next {       background-color: #000;       padding: 0 10px;    ...
javascript的面向对象编程基础教程
本教程详解javascript的面向对象编程基础教程 重新认识面向对象为了说明 JavaScript 是一门彻底的面向对象的语言,首先有必要从面向对象的概念着手 , 探讨一下面向对象中的几个概念: 一切事物皆对象 对象具有封装和继承特性 对象与对象之间使用消息通信,各自存在信息隐藏 以这三点做为依据,C++ 是半面向对象半面向过程...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……