Animated Donut/Pie/Ring Charts With jQuery And SVG - Donutty

Animated Donut/Pie/Ring Charts With jQuery And SVG - Donutty
File Size: 169 KB
Views Total: 7148
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Donutty is a JavaScript/jQuery charting library which lets you generate smoothly animated, fully scalable Donut/Pie/Ring Charts or Circular/Radial progressbars using SVG and CSS3 animations.

Also comes with a vanilla JavaScript version which allows you to implement the charting library without any 3rd dependencies.

Install & download:

# Yarn
$ yarn add donutty

# NPM
$ npm install donutty --save

How to use it (jQuery Version):

1. Load the latest jQuery (slim build) and the JavaScript file 'donutty-jquery.js' in the document.

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

2. To create a default chart, just add the 'data-donutty' attribute to the placeholder element and done.

<div data-donutty></div>

3. Or call the function on the placeholder element:

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

4. Customize the chart via data-OPTION attributes or by passing the options to the donutty() method as follows:

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

5. All default configuration options.

const myChart = $("#example").donutty({

      // min/max values
      min: 0,
      max: 100,

      // current value
      value: 50,

      // rounded edges or not
      round: true,

      // complete circle or not
      circle: true,

      // padding in pixels
      padding: 4,

      // radius in pixels
      radius: 50,

      // thickness in pixels
      thickness: 10,

      // background color
      bg: "rgba(70, 130, 180, 0.15)",

      // bar color
      color: "mediumslateblue",

      // transition effect
      transition: "all 1.2s cubic-bezier(0.57, 0.13, 0.18, 0.98)"
      
});

6. Customize the text displayed in the chart using the text function.

const myChart = $("#example").donutty({

      text: function( state ) {
        return ( state.value / ( state.max - state.min ) * 100 ) + "%";
        // return the percentage of the donut
      }
      
});

7. Update the options/values/stats of the chart.

// min, max, value
myChart.set( "value", 60 )

// min, max, value, bg, color, etc
myChart.setState({ 
  options here
})

Changelog:

v2.0.0 (2019-11-04)

  • Fix responsiveness, classList, bump packages

v1.2.3 (2019-06-28)

  • Fix width/height on Firefox

v1.2.2 (2019-06-26)

  • code refactor

v1.2.1 (2019-06-10)

  • No longer throws error about styling an non-existing text element.

 


This awesome jQuery plugin is developed by simeydotme. For more Advanced Usages, please check the demo page or visit the official website.