/** * 创建进度条 组件 */ function CreateSpeed(option){ this.option = option; this.isFirstLoad = true; this.init(); } CreateSpeed.prototype = { init:function () { this.createSpeed(); }, createSpeed:function () { var _view_ = this; var html = ''; html += '
'; html += '
'; html += ''+_view_.option.title+''; html += '
'; html += '
'; html += '
'; html += '
'; $("#"+_view_.option.id).append(html); }, setData:function (series) { var _view_ = this; function toPoint(point){ var str=Number(point*100).toFixed(1); str+="%"; return str; } var html = ''; series.forEach(function (item,index) { html += '
  • '+item["name"]+''+item["data"]+'
  • '; }); $("#"+_view_.option.id + " ul").html(html); //动画效果加载数据 if(_view_.isFirstLoad){ series.forEach(function (item,index) { var dataNum = null; if(_view_.option.max === null){ dataNum = item["data"]; }else{ dataNum = toPoint(item["data"]/_view_.option.max); } $("#"+_view_.option.id+index).animate({ width:dataNum },2000); }); _view_.isFirstLoad = false; }else{ series.forEach(function (item,index) { var dataNum = null; if(_view_.option.max === null){ dataNum = item["data"]; }else{ dataNum = toPoint(item["data"]/_view_.option.max); } $("#"+_view_.option.id+index).width({ width:dataNum }) }); } } };