Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
# easyPieChart
2
 
3
> Lightweight plugin to render simple, animated and retina optimized pie charts
4
 
5
![Version](http://img.shields.io/version/2.1.5.png?color=green)
6
[![Build Status](https://travis-ci.org/rendro/easy-pie-chart.png)](https://travis-ci.org/rendro/easy-pie-chart)
7
[![Dependencies Status](https://david-dm.org/rendro/easy-pie-chart/dev-status.png)](https://david-dm.org/rendro/easy-pie-chart)
8
[![Analytics](https://ga-beacon.appspot.com/UA-46840672-1/easy-pie-chart/readme)](https://github.com/igrigorik/ga-beacon)
9
 
10
 
11
 
12
## Features
13
[![](https://github.com/rendro/easy-pie-chart/raw/master/demo/img/easy-pie-chart.png)](http://drbl.in/ezuc)
14
 
15
* highly customizable
16
* very easy to implement
17
* resolution independent (retina optimized)
18
* uses `requestAnimationFrame` for smooth animations on modern devices and
19
* works in all modern browsers, even in IE7+ with [excanvas](https://code.google.com/p/explorercanvas/wiki/Instructions)
20
 
21
#### framework support
22
 
23
* Vanilla JS *(no dependencies)* (~872 bytes)
24
* jQuery plugin (~921 bytes)
25
* Angular Module (~983 bytes)
26
 
27
 
28
 
29
## Get started
30
#### Installation
31
 
32
You can also use [bower](http://bower.io) to install the component:
33
 
34
```
35
$ bower install jquery.easy-pie-chart
36
```
37
 
38
#### jQuery
39
 
40
To use the easy pie chart plugin you need to load the current version of jQuery (> 1.6.4) and the source of the plugin.
41
 
42
```html
43
<div class="chart" data-percent="73" data-scale-color="#ffb400">73%</div>
44
 
45
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
46
<script src="/path/to/jquery.easy-pie-chart.js"></script>
47
<script>
48
    $(function() {
49
        $('.chart').easyPieChart({
50
            //your options goes here
51
        });
52
    });
53
</script>
54
```
55
 
56
#### Vanilla JS
57
 
58
If you don't want to use jQuery, implement the Vanilla JS version without any dependencies.
59
 
60
```html
61
<div class="chart" data-percent="73">73%</div>
62
 
63
<script src="/path/to/easy-pie-chart.js"></script>
64
<script>
65
    var element = document.querySelector('.chart');
66
    new EasyPieChart(element, {
67
        // your options goes here
68
    });
69
</script>
70
```
71
 
72
#### AngularJS
73
 
74
```html
75
<div ng-controller="chartCtrl">
76
    <div easypiechart options="options" percent="percent"></div>
77
</div>
78
 
79
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
80
<script src="../dist/angular.easypiechart.min.js"></script>
81
<script>
82
    var app = angular.module('app', ['easypiechart']);
83
    app.controller('chartCtrl', ['$scope', function ($scope) {
84
        $scope.percent = 65;
85
        $scope.options = {
86
            animate:{
87
                duration:0,
88
                enabled:false
89
            },
90
            barColor:'#2C3E50',
91
            scaleColor:false,
92
            lineWidth:20,
93
            lineCap:'circle'
94
        };
95
    }]);
96
</script>
97
```
98
 
99
 
100
 
101
## Options
102
You can pass these options to the initialize function to set a custom look and feel for the plugin.
103
 
104
<table>
105
    <tr>
106
        <th>Property (Type)</th>
107
        <th>Default</th>
108
        <th>Description</th>
109
    </tr>
110
    <tr>
111
        <td><strong>barColor</strong></td>
112
        <td>#ef1e25</td>
113
        <td>The color of the curcular bar. You can either pass a valid css color string, or a function that takes the current percentage as a value and returns a valid css color string.</td>
114
    </tr>
115
    <tr>
116
        <td><strong>trackColor</strong></td>
117
        <td>#f2f2f2</td>
118
        <td>The color of the track, or false to disable rendering.</td>
119
    </tr>
120
    <tr>
121
        <td><strong>scaleColor</strong></td>
122
        <td>#dfe0e0</td>
123
        <td>The color of the scale lines, false to disable rendering.</td>
124
    </tr>
125
    <tr>
126
        <td><strong>scaleLength</strong></td>
127
        <td>5</td>
128
        <td>Length of the scale lines (reduces the radius of the chart).</td>
129
    </tr>
130
    <tr>
131
        <td><strong>lineCap</strong></td>
132
        <td>round</td>
133
        <td>Defines how the ending of the bar line looks like. Possible values are: <code>butt</code>, <code>round</code> and <code>square</code>.</td>
134
    </tr>
135
    <tr>
136
        <td><strong>lineWidth</strong></td>
137
        <td>3</td>
138
        <td>Width of the chart line in px.</td>
139
    </tr>
140
    <tr>
141
        <td><strong>size</strong></td>
142
        <td>110</td>
143
        <td>Size of the pie chart in px. It will always be a square.</td>
144
    </tr>
145
        <tr>
146
        <td><strong>rotate</strong></td>
147
        <td>0</td>
148
        <td>Rotation of the complete chart in degrees.</td>
149
    </tr>
150
    <tr>
151
        <td><strong>animate</strong></td>
152
        <td>object</td>
153
        <td>Object with time in milliseconds and boolean for an animation of the bar growing (<code>{ duration: 1000, enabled: true }</code>), or false to deactivate animations.</td>
154
    </tr>
155
    <tr>
156
        <td><strong>easing</strong></td>
157
        <td>defaultEasing</td>
158
        <td>Easing function or string with the name of a <a href="http://gsgd.co.uk/sandbox/jquery/easing/" target="_blank">jQuery easing function</a></td>
159
    </tr>
160
</table>
161
 
162
 
163
 
164
## Callbacks
165
All callbacks will only be called if `animate` is not `false`.
166
 
167
<table>
168
    <tr>
169
        <th>Callback(params, ...)</th>
170
        <th>Description</th>
171
    </tr>
172
    <tr>
173
        <td><strong>onStart(from, to)</strong></td>
174
        <td>Is called at the start of any animation.</td>
175
    </tr>
176
    <tr>
177
        <td><strong>onStep(from, to, currentValue)</strong></td>
178
        <td>Is called during animations providing the current value (the method is scoped to the context of th eplugin, so you can access the DOM element via <code>this.el</code>).</td>
179
    </tr>
180
    <tr>
181
        <td><strong>onStop(from, to)</strong></td>
182
        <td>Is called at the end of any animation.</td>
183
    </tr>
184
</table>
185
 
186
 
187
 
188
## Plugin api
189
#### jQuery
190
 
191
```javascript
192
$(function() {
193
    // instantiate the plugin
194
    ...
195
    // update
196
    $('.chart').data('easyPieChart').update(40);
197
    ...
198
    // disable animation
199
    $('.chart').data('easyPieChart').disableAnimation();
200
    ...
201
    // enable animation
202
    $('.chart').data('easyPieChart').enableAnimation();
203
});
204
```
205
 
206
#### Vanilla JS
207
 
208
```javascript
209
// instantiate the plugin
210
var chart = new EasyPieChart(element, options);
211
// update
212
chart.update(40);
213
// disable animation
214
chart.disableAnimation();
215
// enable animation
216
chart.enableAnimation();
217
```
218
 
219
###### Using a gradient
220
 
221
```
222
new EasyPieChart(element, {
223
  barColor: function(percent) {
224
    var ctx = this.renderer.ctx();
225
    var canvas = this.renderer.canvas();
226
    var gradient = ctx.createLinearGradient(0,0,canvas.width,0);
227
        gradient.addColorStop(0, "#ffe57e");
228
        gradient.addColorStop(1, "#de5900");
229
    return gradient;
230
  }
231
});
232
```
233
 
234
#### AngularJS
235
 
236
For a value binding you need to add the `percent` attribute and bind it to your controller.
237
 
238
#### RequireJS
239
 
240
When using [RequireJS](http://requirejs.org) you can define your own name. Examples can be found in the `demo/requirejs.html`.
241
 
242
 
243
## Browser Support
244
Native support
245
 
246
* Chrome
247
* Safari
248
* FireFox
249
* Opera
250
* Internet Explorer 9+
251
 
252
Support for Internet Explorer 7 and 8 with [excanvas](https://code.google.com/p/explorercanvas/wiki/Instructions) polyfill.
253
 
254
 
255
 
256
## Test
257
To run the test just use the karma adapter of grunt: `grunt test`
258
 
259
 
260
 
261
## Credits
262
Thanks to [Rafal Bromirski](http://www.paranoida.com/) for designing [this dribble shot](http://drbl.in/ezuc) which inspired me building this plugin.
263
 
264
 
265
 
266
## Copyright
267
Copyright (c) 2014 Robert Fleischmann, contributors. Released under the MIT, GPL licenses