Circliful 基于 jQuery 显示圆形循环统计插件

发布于 2018-06-18 22:44:39 字数 11660 浏览 3068 评论 0

Circliful 是一个基于 jQuery 的插件,用于显示圆形循环统计,使用 SVG 绘画图形,不适用任何图片,兼容现在主流的浏览器,支持响应式布局,有许多自定义选择可供配置。

Circliful 基于 jQuery 显示圆形循环统计插件

使用方法

首先引入 Circliful 和 jQuery 文件

<link href="css/jquery.circliful.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="js/jquery.circliful.min.js"></script>

在 jQuery 的以下版本测试通过:

  • 1.12.4
  • 2.2.4
  • 3.1.0

编写一个 DIV 容器来放置图形,设置一个唯一的 ID ,这个 DIV 控制了图形的大小

<div class="row">
    <div class="col-lg-2">
        <div id="test-circle"></div>
    </div>
</div>

最后在文件的末尾调用插件

<script>
    $( document ).ready(function() {
	$("#your-circle").circliful({
                animationStep: 5,
                foregroundBorderWidth: 5,
                backgroundBorderWidth: 15,
                percent: 75
           });
   });
</script>

可选参数

Circle

OptionDescriptionTypeDefault
foregroundColorcolor of the foreground circle (no color add value 'none')RGB or string#3498DB
backgroundColorcolor of the background circle (no color add value 'none')RGB or string#eee
fillColorfill color of circleRGB or stringnone
pointColorfill color of point circleRGB or stringnone
pointSizeSize of point circleint28.5
foregroundBorderWidthwidth of foreground circle borderint15
backgroundBorderWidthwidth of background circle borderint15
animationif the circle should be animated initiallyint1
animationStepcan be 1 to 100, how fast or slow the animation should beint5
progresColorchange color of foreground circle as percents changed({ 50: '#FF6C00', 60: '#FF6C00'})objectnull
halfCircledraw half circle see example bellowbooleanfalse
animateInViewanimate circle on scroll into viewbooleanfalse

Percentage Text

OptionDescriptionTypeDefault
fontColorcolor of the percentageRGB#aaa
percentageYvertical position of the percentage textinteger100
percentageXhorizontal position of the percentage textinteger100
percentcan be 1 to 100integer75
percentageTextSizefont size of the percentage textinteger22
textAdditionalCssadditional css for the percentage textstring''
targetPercentdraws a circle around the main circleinteger0
targetTextSizefont size of the target percentageinteger17
targetColorfill color of the target circleRGB#2980B9
textinfo text shown bellow the percentage in the circlestring''
textStylecss inline style you want to add to your info textstring''
textColorfont color of the info textRGB#666
textYvertical position of your info textintegernull
textXhorizontal position of your info textintegernull
textBelowaligns string of "text" property centered below the circlebooleanfalse
multiPercentageturns multiple bars on if set to 1integer1
percentagesarray of percent, color and title for each circlearray[]
multiPercentageLegendshow a legend with title, color and percentage on the rightinteger0
noPercentageSignto hide the percentage signbooleanfalse
replacePercentageByTextreplace the percentage shown in the circle by textstringnull
decimalsnumber of decimal places to showinteger0
alwaysDecimalsshows decimals while animating instead of only at the end or if less than 1booleanfalse
titletitle of the circlestringCircle Chart
descriptiondescription of the circlestring''

Icon

OptionDescriptionTypeDefault
iconfont awesome icon, details bellowstringnone
iconSizefont size of the iconinteger30
iconColorcolor of the iconRGB#ccc
iconPositionposition of the icon (top, bottom, left, right or middle)stringtop
iconDecorationdecoration of icon percetagebooleantrue

使用数据属性

所有选项也可以设置为数据属性,例如:

<div id="test-circle" data-animation="1" data-animationStep="5" data-percent="58"></div>

使用举例

接下来分享一些使用的方法:

半圆

$("#test-circle5").circliful({
    animationStep: 5,
    foregroundBorderWidth: 5,
    backgroundBorderWidth: 15,
    percent: 80,
    halfCircle: 1,
});

多个环

$("#test-circle").circliful({
        animation: 1,
        animationStep: 5,
        foregroundBorderWidth: 7,
        backgroundBorderWidth: 7,
        textSize: 28,
        textStyle: 'font-size: 12px;',
        textColor: '#666',
        multiPercentage: 1,
        percentages: [
        	{'percent': 10, 'color': '#3180B8', 'title': 'Gryffindor' },
		{'percent': 30, 'color': '#4ADBEA', 'title': 'Ravenclaw' },
		{'percent': 50, 'color': '#49EBA8', 'title': 'Hufflepuff' },
		{'percent': 70, 'color': '#FFCA35', 'title': 'Slytherin' }
        ],
        multiPercentageLegend: 1,
    replacePercentageByText: '',
        backgroundColor: '#eee',
        icon: 'f0d0',
        iconPosition: 'middle',
        iconColor: '#273B4E'
    });

使用回调函数

在图形生成以后

$("#circli").circliful({
        animation: 1,
        animationStep: 10,
        foregroundBorderWidth: 5,
        backgroundColor: "none",
        fillColor: '#eee',
        percent: 75,
        iconColor: '#3498DB',
        icon: 'f206',
        iconSize: '40',
        iconPosition: 'middle',
        start:50,
        showPercent:1,
        target:0
    }, function(){
        alert('done !');
    });

使用 Font Awesome 图标

先引入 font-awesome.css 文件,然后找到并复制图标的 Unicode 代码,粘贴在初始化插件的配置参数里面:

.fa-hdd-o:before {
    content: "\f0a0";
}

复制 f0a0 到参数 ICON 中 { icon: 'f0a0' }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

文章
评论
84965 人气
更多

推荐作者

动次打次papapa

文章 0 评论 0

我是有多爱你

文章 0 评论 0

linces

文章 0 评论 0

玍銹的英雄夢

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文