jQuery和SVG 动画甜甜圈/饼图/环形图 Donutty

  • 源码大小:194.3KB
  • 所需积分:1积分
  • 源码编号:19JP-3346
  • 浏览次数:674次
  • 最后更新:2023年06月03日
  • 所属栏目:图表
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Donutty是一个JavaScript/jQuery图表库,可以使用SVG和CSS3动画生成平滑动画、完全可扩展的Donut/Pie/RingCharts或Circular/Radial进度条。

还附带了一个普通的JavaScript版本,它允许您在没有任何第三依赖项的情况下实现图表库。

参见:

  • 10个最佳循环/径向进度条JavaScript插件

安装和下载:

  1. # Yarn
  2. $ yarn add donutty
  3.  
  4. # NPM
  5. $ npm install donutty --save

如何使用它(jQuery版本):

1.在文档中加载最新的jQuery(slim build)和JavaScript文件“donutty jQuery.js”。

  1. <script src="jquery.slim.min.js"></script>
  2. <script src="dist/donutty-jquery.js"></script>

2.要创建默认图表,只需将“data donutty”属性添加到占位符元素即可。

  1. <div data-donutty></div>

3.或者调用占位符元素上的函数:

  1. const myChart = $("#example").donutty({
  2. // options here
  3. });

4.通过自定义图表数据选项属性,或者将选项传递给donutty()方法,如下所示:

  1. <div data-donutty
  2. data-radius=20
  3. data-thickness=40
  4. data-padding=0
  5. data-round=false
  6. data-color="lightcoral"
  7. data-value=80
  8. ...>
  9. </div>
  1. // or
  2. const myChart = $("#example").donutty({
  3. min: -100,
  4. max: 100,
  5. value: 50
  6. });

5.所有默认配置选项。

  1. const myChart = $("#example").donutty({
  2.  
  3. // min/max values
  4. min: 0,
  5. max: 100,
  6.  
  7. // current value
  8. value: 50,
  9.  
  10. // rounded edges or not
  11. round: true,
  12.  
  13. // complete circle or not
  14. circle: true,
  15.  
  16. // padding in pixels
  17. padding: 4,
  18.  
  19. // radius in pixels
  20. radius: 50,
  21.  
  22. // thickness in pixels
  23. thickness: 10,
  24.  
  25. // background color
  26. bg: "rgba(70, 130, 180, 0.15)",
  27.  
  28. // bar color
  29. color: "mediumslateblue",
  30.  
  31. // transition effect
  32. transition: "all 1.2s cubic-bezier(0.57, 0.13, 0.18, 0.98)",
  33.  
  34. // a String that can accept "rtl" for right-to-left modes
  35. dir: false,
  36.  
  37. // or "bottom"
  38. // start the Donut's filling from the Top instead of always from the Bottom.
  39. anchor: "top",
  40. });

6.自定义图表中显示的文本、标题和说明。

  1. const myChart = $("#example").donutty({
  2.  
  3. text: function( state ) {
  4. return ( state.value / ( state.max - state.min ) * 100 ) + "%";
  5. // return the percentage of the donut
  6. },
  7.  
  8. title: function() {
  9. return "Donut Chart Graphic";
  10. },
  11.  
  12. desc: function( v ) {
  13. return "A donut chart ranging from " + v.min + " to " + v.max + " with a current value of " + v.value + ".";
  14. };
  15. });

7.更新图表的选项/值/统计数据。

  1. // min, max, value
  2. myChart.set( "value", 60 )
  3.  
  4. // min, max, value, bg, color, etc
  5. myChart.setState({
  6. options here
  7. })

更新日志:

v2.4.0版本(2022-10-19)

  • 现在可以从顶部开始填充甜甜圈,而不是总是从底部开始。

v2.3.1 (2021-12-08)

  • 修复rotate safari错误

第2.2.0版(2021-01-31)

  • 添加辅助功能支持

v2.0.0版本(2019-11-04)

  • 修复响应性、classList、bump包

v1.2.3 (2019-06-28)

  • 在Firefox上修复宽度/高度

v1.2.2 (2019-06-26)

  • 代码重构器

v1.2.1(2019年6月10日)

  • 不再引发关于设置不存在的文本元素样式的错误。

 

预览截图