forked from JodiWarren/chart-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
769 lines (601 loc) · 31.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
<!DOCTYPE html>
<!-- saved from url=(0107)http://webcache.googleusercontent.com/search?q=cache:AoeIcSxetgsJ:www.chartjs.org/docs/+&cd=1&hl=en&ct=clnk -->
<html class="wf-proximanova-n4-active wf-proximanova-n6-active wf-active"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--<base href="http://www.chartjs.org/docs/">--><base href=".">
</head><body>
<div style="position:relative">
<title>Chart.js Documentation</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="chartjs.js"></script>
<div class="redBorder"></div>
<div class="greenBorder"></div>
<div class="yellowBorder"></div>
<div id="wrapper">
<nav>
<dl>
<dt><a href="http://www.chartjs.org/docs/#gettingStarted">Getting started</a></dt><dd><a href="http://www.chartjs.org/docs/#gettingStarted-includeChart.js">Include Chart.js</a></dd><dd><a href="http://www.chartjs.org/docs/#gettingStarted-creatingAChart">Creating a chart</a></dd><dt><a href="http://www.chartjs.org/docs/#lineChart">Line chart</a></dt><dd><a href="http://www.chartjs.org/docs/#lineChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#lineChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#lineChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#lineChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#barChart">Bar chart</a></dt><dd><a href="http://www.chartjs.org/docs/#barChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#barChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#barChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#barChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#radarChart">Radar chart</a></dt><dd><a href="http://www.chartjs.org/docs/#radarChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#radarChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#radarChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#radarChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#polarAreaChart">Polar area chart</a></dt><dd><a href="http://www.chartjs.org/docs/#polarAreaChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#polarAreaChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#polarAreaChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#polarAreaChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#pieChart">Pie chart</a></dt><dd><a href="http://www.chartjs.org/docs/#pieChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#pieChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#pieChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#pieChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#doughnutChart">Doughnut chart</a></dt><dd><a href="http://www.chartjs.org/docs/#doughnutChart-introduction">Introduction</a></dd><dd><a href="http://www.chartjs.org/docs/#doughnutChart-exampleUsage">Example usage</a></dd><dd><a href="http://www.chartjs.org/docs/#doughnutChart-dataStructure">Data structure</a></dd><dd><a href="http://www.chartjs.org/docs/#doughnutChart-chartOptions">Chart options</a></dd><dt><a href="http://www.chartjs.org/docs/#generalIssues">General issues</a></dt><dd><a href="http://www.chartjs.org/docs/#generalIssues-chartInteractivity">Chart interactivity</a></dd><dd><a href="http://www.chartjs.org/docs/#generalIssues-browserSupport">Browser support</a></dd><dd><a href="http://www.chartjs.org/docs/#generalIssues-bugs&Issues">Bugs & issues</a></dd><dd><a href="http://www.chartjs.org/docs/#generalIssues-license">License</a></dd></dl>
</nav>
<div id="contentWrapper">
<h1 id="mainHeader">Chart.js Documentation</h1>
<h2 id="introText">Everything you need to know to create great looking charts using Chart.js</h2>
<article id="gettingStarted">
<h1>Getting started</h1>
<h2 id="gettingStarted-includeChart.js">Include Chart.js</h2>
<p>First we need to include the Chart.js library on the page. The library occupies a global variable of <code>Chart</code>.</p>
<pre data-type="html"><code><script src="Chart.js"></script></code></pre>
<h2 id="gettingStarted-creatingAChart">Creating a chart</h2>
<p>To create a chart, we need to instantiate the Chart class. To do this, we need to pass in the 2d context of where we want to draw the chart. Here's an example.</p>
<pre data-type="html"><code><canvas id="myChart" width="400" height="400"></canvas></code></pre>
<pre data-type="javascript"><code>//Get the context of the canvas element we want to select
var ctx = document.getElementbyId("myChart").getContext("2d");
var myNewChart = new Chart(ctx).PolarArea(data);</code></pre>
<p>We can also get the context of our canvas with jQuery. To do this, we need to get the DOM node out of the jQuery collection, and call the <code>getContext("2d")</code> method on that.</p>
<pre data-type="javascript"><code>//Get context with jQuery - using jQuery's .get() method.
var ctx = $("#myChart").get(0).getContext("2d");
//This will get the first returned node in the jQuery collection.
var myNewChart = new Chart(ctx);</code></pre>
<p>After we've instantiated the Chart class on the canvas we want to draw on, Chart.js will handle the scaling for retina displays.</p>
<p>With the Chart class set up, we can go on to create one of the charts Chart.js has available. In the example below, we would be drawing a Polar area chart.</p>
<pre data-type="javascript"><code>new Chart(ctx).PolarArea(data,options);</code></pre>
<p>We call a method of the name of the chart we want to create. We pass in the data for that chart type, and the options for that chart as parameters. Chart.js will merge the options you pass in with the default options for that chart type.</p>
</article>
<article id="lineChart">
<h1>Line chart</h1>
<h2 id="lineChart-introduction">Introduction</h2>
<p>A line chart is a way of plotting data points on a line.</p>
<p>Often, it is used to show trend data, and the comparison of two data sets.</p>
<h2 id="lineChart-exampleUsage">Example usage</h2>
<canvas id="line" data-type="Line" width="600" height="400"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).Line(data,options);</code></pre>
<h2 id="lineChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="line">var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28,48,40,19,96,27,100]
}
]
}</code></pre>
<p>The line chart requires an array of labels for each of the data points. This is show on the X axis.</p>
<p>The data for line charts is broken up into an array of datasets. Each dataset has a colour for the fill, a colour for the line and colours for the points and strokes of the points. These colours are strings just like CSS. You can use RGBA, RGB, HEX or HSL notation.</p>
<h2 id="lineChart-chartOptions">Chart options</h2>
<pre data-type="javascript"><code>Line.defaults = {
//Boolean - If we show the scale above the chart data
scaleOverlay : false,
//Boolean - If we want to override with a hard coded scale
scaleOverride : false,
//** Required if scaleOverride is true **
//Number - The number of steps in a hard coded scale
scaleSteps : null,
//Number - The value jump in the hard coded scale
scaleStepWidth : null,
//Number - The scale starting value
scaleStartValue : null,
//String - Colour of the scale line
scaleLineColor : "rgba(0,0,0,.1)",
//Number - Pixel width of the scale line
scaleLineWidth : 1,
//Boolean - Whether to show labels on the scale
scaleShowLabels : false,
//Interpolated JS string - can access value
scaleLabel : "<%=value%>",
//String - Scale label font declaration for the scale label
scaleFontFamily : "'Arial'",
//Number - Scale label font size in pixels
scaleFontSize : 12,
//String - Scale label font weight style
scaleFontStyle : "normal",
//String - Scale label font colour
scaleFontColor : "#666",
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines : true,
//String - Colour of the grid lines
scaleGridLineColor : "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth : 1,
//Boolean - Whether the line is curved between points
bezierCurve : true,
//Boolean - Whether to show a dot for each point
pointDot : true,
//Number - Radius of each point dot in pixels
pointDotRadius : 3,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth : 1,
//Boolean - Whether to show a stroke for datasets
datasetStroke : true,
//Number - Pixel width of dataset stroke
datasetStrokeWidth : 2,
//Boolean - Whether to fill the dataset with a colour
datasetFill : true,
//Boolean - Whether to animate the chart
animation : true,
//Number - Number of animation steps
animationSteps : 60,
//String - Animation easing effect
animationEasing : "easeOutQuart",
//Function - Fires when the animation is complete
onAnimationComplete : null
}</code></pre>
</article>
<article id="barChart">
<h1>Bar chart</h1>
<h2 id="barChart-introduction">Introduction</h2>
<p>A bar chart is a way of showing data as bars.</p>
<p>It is sometimes used to show trend data, and the comparison of multiple data sets side by side.</p>
<h2 id="barChart-exampleUsage">Example usage</h2>
<canvas id="bar" data-type="Bar" width="600" height="400"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).Bar(data,options);</code></pre>
<h2 id="barChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="bar">var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
data : [28,48,40,19,96,27,100]
}
]
}</code></pre>
<p>The bar chart has the a very similar data structure to the line chart, and has an array of datasets, each with colours and an array of data. Again, colours are in CSS format.</p>
<p>We have an array of labels too for display. In the example, we are showing the same data as the previous line chart example.</p>
<h2 id="barChart-chartOptions">Chart options</h2>
<pre data-type="javascript"><code>Bar.defaults = {
//Boolean - If we show the scale above the chart data
scaleOverlay : false,
//Boolean - If we want to override with a hard coded scale
scaleOverride : false,
//** Required if scaleOverride is true **
//Number - The number of steps in a hard coded scale
scaleSteps : null,
//Number - The value jump in the hard coded scale
scaleStepWidth : null,
//Number - The scale starting value
scaleStartValue : null,
//String - Colour of the scale line
scaleLineColor : "rgba(0,0,0,.1)",
//Number - Pixel width of the scale line
scaleLineWidth : 1,
//Boolean - Whether to show labels on the scale
scaleShowLabels : false,
//Interpolated JS string - can access value
scaleLabel : "<%=value%>",
//String - Scale label font declaration for the scale label
scaleFontFamily : "'Arial'",
//Number - Scale label font size in pixels
scaleFontSize : 12,
//String - Scale label font weight style
scaleFontStyle : "normal",
//String - Scale label font colour
scaleFontColor : "#666",
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines : true,
//String - Colour of the grid lines
scaleGridLineColor : "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth : 1,
//Boolean - If there is a stroke on each bar
barShowStroke : true,
//Number - Pixel width of the bar stroke
barStrokeWidth : 2,
//Number - Spacing between each of the X value sets
barValueSpacing : 5,
//Number - Spacing between data sets within X values
barDatasetSpacing : 1,
//Boolean - Whether to animate the chart
animation : true,
//Number - Number of animation steps
animationSteps : 60,
//String - Animation easing effect
animationEasing : "easeOutQuart",
//Function - Fires when the animation is complete
onAnimationComplete : null
}</code></pre>
</article>
<article id="radarChart">
<h1>Radar chart</h1>
<h2 id="radarChart-introduction">Introduction</h2>
<p>A radar chart is a way of showing multiple data points and the variation between them.</p>
<p>They are often useful for comparing the points of two or more different data sets</p>
<h2 id="radarChart-exampleUsage">Example usage</h2>
<canvas id="radar" data-type="Radar" width="400" height="400"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).Radar(data,options);</code></pre>
<h2 id="radarChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="radar">var data = {
labels : ["Eating","Drinking","Sleeping","Designing","Coding","Partying","Running"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28,48,40,19,96,27,100]
}
]
}</code></pre>
<p>For a radar chart, usually you will want to show a label on each point of the chart, so we include an array of strings that we show around each point in the chart. If you do not want this, you can either not include the array of labels, or choose to hide them in the chart options.</p>
<p>For the radar chart data, we have an array of datasets. Each of these is an object, with a fill colour, a stroke colour, a colour for the fill of each point, and a colour for the stroke of each point. We also have an array of data values.</p>
<h2 id="radarChart-chartOptions">Chart options</h2>
<pre data-type="javascript"><code>Radar.defaults = {
//Boolean - If we show the scale above the chart data
scaleOverlay : false,
//Boolean - If we want to override with a hard coded scale
scaleOverride : false,
//** Required if scaleOverride is true **
//Number - The number of steps in a hard coded scale
scaleSteps : null,
//Number - The value jump in the hard coded scale
scaleStepWidth : null,
//Number - The centre starting value
scaleStartValue : null,
//Boolean - Whether to show lines for each scale point
scaleShowLine : true,
//String - Colour of the scale line
scaleLineColor : "rgba(0,0,0,.1)",
//Number - Pixel width of the scale line
scaleLineWidth : 1,
//Boolean - Whether to show labels on the scale
scaleShowLabels : false,
//Interpolated JS string - can access value
scaleLabel : "<%=value%>",
//String - Scale label font declaration for the scale label
scaleFontFamily : "'Arial'",
//Number - Scale label font size in pixels
scaleFontSize : 12,
//String - Scale label font weight style
scaleFontStyle : "normal",
//String - Scale label font colour
scaleFontColor : "#666",
//Boolean - Show a backdrop to the scale label
scaleShowLabelBackdrop : true,
//String - The colour of the label backdrop
scaleBackdropColor : "rgba(255,255,255,0.75)",
//Number - The backdrop padding above & below the label in pixels
scaleBackdropPaddingY : 2,
//Number - The backdrop padding to the side of the label in pixels
scaleBackdropPaddingX : 2,
//Boolean - Whether we show the angle lines out of the radar
angleShowLineOut : true,
//String - Colour of the angle line
angleLineColor : "rgba(0,0,0,.1)",
//Number - Pixel width of the angle line
angleLineWidth : 1,
//String - Point label font declaration
pointLabelFontFamily : "'Arial'",
//String - Point label font weight
pointLabelFontStyle : "normal",
//Number - Point label font size in pixels
pointLabelFontSize : 12,
//String - Point label font colour
pointLabelFontColor : "#666",
//Boolean - Whether to show a dot for each point
pointDot : true,
//Number - Radius of each point dot in pixels
pointDotRadius : 3,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth : 1,
//Boolean - Whether to show a stroke for datasets
datasetStroke : true,
//Number - Pixel width of dataset stroke
datasetStrokeWidth : 2,
//Boolean - Whether to fill the dataset with a colour
datasetFill : true,
//Boolean - Whether to animate the chart
animation : true,
//Number - Number of animation steps
animationSteps : 60,
//String - Animation easing effect
animationEasing : "easeOutQuart",
//Function - Fires when the animation is complete
onAnimationComplete : null
}</code></pre>
</article>
<article id="polarAreaChart">
<h1>Polar area chart</h1>
<h2 id="polarAreaChart-introduction">Introduction</h2>
<p>Polar area charts are similar to pie charts, but each segment has the same angle - the radius of the segment differs depending on the value.</p>
<p>This type of chart is often useful when we want to show a comparison data similar to a pie chart, but also show a scale of values for context.</p>
<h2 id="polarAreaChart-exampleUsage">Example usage</h2>
<canvas id="polarArea" data-type="PolarArea" width="300" height="300"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).PolarArea(data,options);</code></pre>
<h2 id="polarAreaChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="polarArea">var data = [
{
value : 30,
color: "#D97041"
},
{
value : 90,
color: "#C7604C"
},
{
value : 24,
color: "#21323D"
},
{
value : 58,
color: "#9D9B7F"
},
{
value : 82,
color: "#7D4F6D"
},
{
value : 8,
color: "#584A5E"
}
]</code></pre>
<p>As you can see, for the chart data you pass in an array of objects, with a value and a colour. The <code>value</code> attribute should be a number, while the <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
<h2 id="polarAreaChart-chartOptions">Chart options</h2>
<p>These are the default chart options. By passing in an object with any of these attributes, Chart.js will merge these objects and the graph accordingly. Explanations of each option are commented in the code below.</p>
<pre data-type="javascript"><code>PolarArea.defaults = {
//Boolean - Whether we show the scale above or below the chart segments
scaleOverlay : true,
//Boolean - If we want to override with a hard coded scale
scaleOverride : false,
//** Required if scaleOverride is true **
//Number - The number of steps in a hard coded scale
scaleSteps : null,
//Number - The value jump in the hard coded scale
scaleStepWidth : null,
//Number - The centre starting value
scaleStartValue : null,
//Boolean - Show line for each value in the scale
scaleShowLine : true,
//String - The colour of the scale line
scaleLineColor : "rgba(0,0,0,.1)",
//Number - The width of the line - in pixels
scaleLineWidth : 1,
//Boolean - whether we should show text labels
scaleShowLabels : true,
//Interpolated JS string - can access value
scaleLabel : "<%=value%>",
//String - Scale label font declaration for the scale label
scaleFontFamily : "'Arial'",
//Number - Scale label font size in pixels
scaleFontSize : 12,
//String - Scale label font weight style
scaleFontStyle : "normal",
//String - Scale label font colour
scaleFontColor : "#666",
//Boolean - Show a backdrop to the scale label
scaleShowLabelBackdrop : true,
//String - The colour of the label backdrop
scaleBackdropColor : "rgba(255,255,255,0.75)",
//Number - The backdrop padding above & below the label in pixels
scaleBackdropPaddingY : 2,
//Number - The backdrop padding to the side of the label in pixels
scaleBackdropPaddingX : 2,
//Boolean - Stroke a line around each segment in the chart
segmentShowStroke : true,
//String - The colour of the stroke on each segement.
segmentStrokeColor : "#fff",
//Number - The width of the stroke value in pixels
segmentStrokeWidth : 2,
//Boolean - Whether to animate the chart or not
animation : true,
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect.
animationEasing : "easeOutBounce",
//Boolean - Whether to animate the rotation of the chart
animateRotate : true,
//Boolean - Whether to animate scaling the chart from the centre
animateScale : false,
//Function - This will fire when the animation of the chart is complete.
onAnimationComplete : null
}</code></pre>
</article>
<article id="pieChart">
<h1>Pie chart</h1>
<h2 id="pieChart-introduction">Introduction</h2>
<p>Pie charts are probably the most commonly used chart there are. They are divided into segments, the arc of each segment shows a the proportional value of each piece of data.</p>
<p>They are excellent at showing the relational proportions between data.</p>
<h2 id="pieChart-exampleUsage">Example usage</h2>
<canvas id="pie" data-type="Pie" width="400" height="400"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).Pie(data,options);</code></pre>
<h2 id="pieChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="pie">var data = [
{
value: 30,
color:"#F38630"
},
{
value : 50,
color : "#E0E4CC"
},
{
value : 100,
color : "#69D2E7"
}
]</code></pre>
<p>For a pie chart, you must pass in an array of objects with a <code>value</code> and a <code>color</code> property. The <code>value</code> attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
<h2 id="pieChart-chartOptions">Chart options</h2>
<p>These are the default options for the Pie chart. Pass in an object with any of these attributes to override them.
</p><pre data-type="javascript"><code>Pie.defaults = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//Boolean - Whether we should animate the chart
animation : true,
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : "easeOutBounce",
//Boolean - Whether we animate the rotation of the Pie
animateRotate : true,
//Boolean - Whether we animate scaling the Pie from the centre
animateScale : false,
//Function - Will fire on animation completion.
onAnimationComplete : null
}</code></pre>
</article>
<article id="doughnutChart">
<h1>Doughnut chart</h1>
<h2 id="doughnutChart-introduction">Introduction</h2>
<p>Doughnut charts are similar to pie charts, however they have the centre cut out, and are therefore shaped more like a doughnut than a pie!</p>
<p>They are aso excellent at showing the relational proportions between data.</p>
<h2 id="doughnutChart-exampleUsage">Example usage</h2>
<canvas id="doughnut" data-type="Doughnut" width="400" height="400"></canvas>
<pre data-type="javascript"><code>new Chart(ctx).Doughnut(data,options);</code></pre>
<h2 id="doughnutChart-dataStructure">Data structure</h2>
<pre data-type="javascript"><code data-for="doughnut">var data = [
{
value: 30,
color:"#F7464A"
},
{
value : 50,
color : "#E2EAE9"
},
{
value : 100,
color : "#D4CCC5"
},
{
value : 40,
color : "#949FB1"
},
{
value : 120,
color : "#4D5360"
}
]</code></pre>
<p>For a doughnut chart, you must pass in an array of objects with a <code>value</code> and a <code>color</code> property. The <code>value</code> attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
<h2 id="doughnutChart-chartOptions">Chart options</h2>
<p>These are the default options for the doughnut chart. Pass in an object with any of these attributes to override them.
</p><pre data-type="javascript"><code>Doughnut.defaults = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//The percentage of the chart that we cut out of the middle.
percentageInnerCutout : 50,
//Boolean - Whether we should animate the chart
animation : true,
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : "easeOutBounce",
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
//Function - Will fire on animation completion.
onAnimationComplete : null
}</code></pre>
</article>
<article id="generalIssues">
<h1>General issues</h1>
<h2 id="generalIssues-chartInteractivity">Chart interactivity</h2>
<p>If you are looking to add interaction as a layer to charts, Chart.js is <strong>not the library for you</strong>. A better option would be using SVG, as this will let you attach event listeners to any of the elements in the chart, as these are all DOM nodes.</p>
<p>Chart.js uses the canvas element, which is a single DOM node, similar in characteristics to a static image. This does mean that it has a wider scope for compatibility, and less memory implications than SVG based charting solutions. The canvas element also allows for saving the contents as a base 64 string, allowing saving the chart as an image. </p>
<p>In SVG, all of the lines, data points and everything you see is a DOM node. As a result of this, complex charts with a lot of intricacies, or many charts on the page will often see dips in performance when scrolling or generating the chart, especially when there are multiple on the page. SVG also has relatively poor mobile support, with Android not supporting SVG at all before version 3.0, and iOS before 5.0. (<a href="http://caniuse.com/svg-html5" target="_blank">caniuse.com/svg-html5</a>).</p>
<h2 id="generalIssues-browserSupport">Browser support</h2>
<p>Browser support for the canvas element is available in all modern & major mobile browsers (<a href="http://caniuse.com/canvas" target="_blank">caniuse.com/canvas</a>).</p>
<p>For IE8 & below, I would recommend using the polyfill ExplorerCanvas - available at <a href="https://code.google.com/p/explorercanvas/" target="_blank">https://code.google.com/p/explorercanvas/</a>. It falls back to Internet explorer's format VML when canvas support is not available. Example use:</p>
<pre data-type="html"><code><head>
<!--[if lte IE 8]>
<script src="excanvas.js"></script>
<![endif]-->
</head></code></pre>
<p>Usually I would recommend feature detection to choose whether or not to load a polyfill, rather than IE conditional comments, however in this case, VML is a Microsoft proprietary format, so it will only work in IE.</p>
<p>Some important points to note in my experience using ExplorerCanvas as a fallback.</p>
<ul>
<li>Initialise charts on load rather than DOMContentReady when using the library, as sometimes a race condition will occur, and it will result in an error when trying to get the 2d context of a canvas.</li>
<li>New VML DOM elements are being created for each animation frame and there is no hardware acceleration. As a result animation is usually slow and jerky, with flashing text. It is a good idea to dynamically turn off animation based on canvas support. I recommend using the excellent <a href="http://modernizr.com/" targer="_blank">Modernizr</a> to do this.</li>
<li>When declaring fonts, the library explorercanvas requires the font name to be in single quotes inside the string. For example, instead of your scaleFontFamily property being simply "Arial", explorercanvas support, use "'Arial'" instead. Chart.js does this for default values.</li>
</ul>
<h2 id="generalIssues-bugs&Issues">Bugs & issues</h2>
<p>Please report these on the Github page - at <a href="https://github.com/nnnick/Chart.js" target="_blank">github.com/nnnick/Chart.js</a>.</p>
<p>New contributions to the library are welcome.</p>
<h2 id="generalIssues-license">License</h2>
<p>Chart.js is open source and available under the <a href="http://opensource.org/licenses/MIT" target="_blank">MIT license</a>.</p>
</article>
</div>
</div>
<script>
$(document).ready(function(){
var $nav = $("nav dl");
$("article").each(function(){
var $el = $(this);
var $h1 = $el.find("h1");
var sectionTitle = $h1.html();
var articleId = $el.attr("id");
var $dt = $("<dt><a href=\"#"+articleId +"\">"+sectionTitle+"</a></dt>");
$dt.find("a").on("click",function(e){
e.preventDefault();
$('html,body').animate({scrollTop: $h1.offset().top},400);
});
$nav.append($dt);
var $subtitles = $el.find("h2");
$subtitles.each(function(){
var $h2 = $(this);
var title = $h2.text();
var newID = articleId + "-" +camelCase(title);
$h2.attr("id",newID);
var $dd = $("<dd><a href=\"#" +newID + "\">" + title + "</a></dd>");
$dd.find("a").on("click",function(e){
e.preventDefault();
$('html,body').animate({scrollTop: $h2.offset().top},400);
})
$nav.append($dd);
});
var $articles = $el.find("article");
});
$("canvas").each(function(){
var $canvas = $(this);
var ctx = this.getContext("2d");
eval($("code[data-for='" + $canvas.attr("id") + "']").text());
var evalString = "new Chart(ctx)." + $canvas.data("type") + "(data);";
eval(evalString);
});
prettyPrint();
function camelCase(str){
var splitString = str.split(" ");
var returnedCamel = splitString[0].toLowerCase();
for (var i=1; i<splitString.length; i++){
returnedCamel += splitString[i].charAt(0).toUpperCase() + splitString[i].substring(1).toLowerCase();
}
return returnedCamel;
}
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-28909194-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</div></body></html>