今天我给大家介绍一款圆形统计图circliful,它基于HTML5的画布和jQuery,无需使用图像轻松实现圆形统计图,而且有很多属性设置,使用起来非常方便。
如何使用circliful
将jquery库文件和jquery.circliful.min.js引入到页面中。
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="js/jquery.circliful.min.js"></script>
添加css样式:
<style>
.circliful {
position: relative;
}
.circle-text, .circle-info, .circle-text-half, .circle-info-half {
width: 100%;
position: absolute;
text-align: center;
display: inline-block;
}
.circle-info, .circle-info-half {
color: #999;
}
.circliful .fa {
margin: -10px 3px 0 3px;
position: relative;
bottom: 4px;
}
</style>
在需要展现统计图的位置加入以下html代码:
<p id="myStat" data-dimension="250" data-text="35%" data-info="New Clients"
data-width="30" data-fontsize="38" data-percent="35" data-fgcolor="#61a9dc"
data-bgcolor="#eee" data-fill="#ddd"></p>
然后在页面中加入调用circliful的代码:
<script>
$( document ).ready(function() {
$('#myStat').circliful();
});
</script>
然后预览页面,你会看到一个非常简洁漂亮的圆形统计图。
选项设置
Circliful提供了丰富的属性选项设置,基于html5的data属性,以下是设置清单。
参数 描述 默认值 data-dimension 圆形图的宽度和高度px 250 data-text 显示在圆圈内侧的文字内容 empty data-info 显示在data-text下的说明信息 empty data-width 圆圈的厚度px 15 data-fontsize 圈内文字大小px 15 data-percent 圆圈统计百分比%,1-100 50 data-fgcolor 圆圈的前景色 #556b2f data-bgcolor 圆圈的背景色 #eeeeee data-fill 圆形的填充背景色 empty data-type 圆形统计类型,可以是"half"或"full" full data-total 数据总量,和data-part配合使用 empty data-part 数据量,与data-total配合使用 empty data-border 圆形样式,可以加边框,如inline或outline empty data-icon Fontawesome图标样式,详情可参照:Fontawesome Website - Icons empty data-icon-size 图标大小 empty data-icon-color 图标颜色 empty
想了解最新版的circliful请访问:https://github.com/pguso/jquery-plugin-circliful
以上就上有关jQuery圆形统计图(百分比)的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。