Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
var ChartsFlotcharts = function() {
2
 
3
    return {
4
        //main function to initiate the module
5
 
6
        init: function() {
7
 
8
            Metronic.addResizeHandler(function() {
9
                Charts.initPieCharts();
10
            });
11
 
12
        },
13
 
14
        initCharts: function() {
15
 
16
            if (!jQuery.plot) {
17
                return;
18
            }
19
 
20
            var data = [];
21
            var totalPoints = 250;
22
 
23
            // random data generator for plot charts
24
 
25
            function getRandomData() {
26
                if (data.length > 0) data = data.slice(1);
27
                // do a random walk
28
                while (data.length < totalPoints) {
29
                    var prev = data.length > 0 ? data[data.length - 1] : 50;
30
                    var y = prev + Math.random() * 10 - 5;
31
                    if (y < 0) y = 0;
32
                    if (y > 100) y = 100;
33
                    data.push(y);
34
                }
35
                // zip the generated y values with the x values
36
                var res = [];
37
                for (var i = 0; i < data.length; ++i) {
38
                    res.push([i, data[i]]);
39
                }
40
 
41
                return res;
42
            }
43
 
44
            //Basic Chart
45
 
46
            function chart1() {
47
                if ($('#chart_1').size() != 1) {
48
                    return;
49
                }
50
 
51
                var d1 = [];
52
                for (var i = 0; i < Math.PI * 2; i += 0.25)
53
                    d1.push([i, Math.sin(i)]);
54
 
55
                var d2 = [];
56
                for (var i = 0; i < Math.PI * 2; i += 0.25)
57
                    d2.push([i, Math.cos(i)]);
58
 
59
                var d3 = [];
60
                for (var i = 0; i < Math.PI * 2; i += 0.1)
61
                    d3.push([i, Math.tan(i)]);
62
 
63
                $.plot($("#chart_1"), [{
64
                    label: "sin(x)",
65
                    data: d1,
66
                    lines: {
67
                        lineWidth: 1,
68
                    },
69
                    shadowSize: 0
70
                }, {
71
                    label: "cos(x)",
72
                    data: d2,
73
                    lines: {
74
                        lineWidth: 1,
75
                    },
76
                    shadowSize: 0
77
                }, {
78
                    label: "tan(x)",
79
                    data: d3,
80
                    lines: {
81
                        lineWidth: 1,
82
                    },
83
                    shadowSize: 0
84
                }], {
85
                    series: {
86
                        lines: {
87
                            show: true,
88
                        },
89
                        points: {
90
                            show: true,
91
                            fill: true,
92
                            radius: 3,
93
                            lineWidth: 1
94
                        }
95
                    },
96
                    xaxis: {
97
                        tickColor: "#eee",
98
                        ticks: [0, [Math.PI / 2, "\u03c0/2"],
99
                            [Math.PI, "\u03c0"],
100
                            [Math.PI * 3 / 2, "3\u03c0/2"],
101
                            [Math.PI * 2, "2\u03c0"]
102
                        ]
103
                    },
104
                    yaxis: {
105
                        tickColor: "#eee",
106
                        ticks: 10,
107
                        min: -2,
108
                        max: 2
109
                    },
110
                    grid: {
111
                        borderColor: "#eee",
112
                        borderWidth: 1
113
                    }
114
                });
115
 
116
            }
117
 
118
            //Interactive Chart
119
 
120
            function chart2() {
121
                if ($('#chart_2').size() != 1) {
122
                    return;
123
                }
124
 
125
                function randValue() {
126
                    return (Math.floor(Math.random() * (1 + 40 - 20))) + 20;
127
                }
128
                var pageviews = [
129
                    [1, randValue()],
130
                    [2, randValue()],
131
                    [3, 2 + randValue()],
132
                    [4, 3 + randValue()],
133
                    [5, 5 + randValue()],
134
                    [6, 10 + randValue()],
135
                    [7, 15 + randValue()],
136
                    [8, 20 + randValue()],
137
                    [9, 25 + randValue()],
138
                    [10, 30 + randValue()],
139
                    [11, 35 + randValue()],
140
                    [12, 25 + randValue()],
141
                    [13, 15 + randValue()],
142
                    [14, 20 + randValue()],
143
                    [15, 45 + randValue()],
144
                    [16, 50 + randValue()],
145
                    [17, 65 + randValue()],
146
                    [18, 70 + randValue()],
147
                    [19, 85 + randValue()],
148
                    [20, 80 + randValue()],
149
                    [21, 75 + randValue()],
150
                    [22, 80 + randValue()],
151
                    [23, 75 + randValue()],
152
                    [24, 70 + randValue()],
153
                    [25, 65 + randValue()],
154
                    [26, 75 + randValue()],
155
                    [27, 80 + randValue()],
156
                    [28, 85 + randValue()],
157
                    [29, 90 + randValue()],
158
                    [30, 95 + randValue()]
159
                ];
160
                var visitors = [
161
                    [1, randValue() - 5],
162
                    [2, randValue() - 5],
163
                    [3, randValue() - 5],
164
                    [4, 6 + randValue()],
165
                    [5, 5 + randValue()],
166
                    [6, 20 + randValue()],
167
                    [7, 25 + randValue()],
168
                    [8, 36 + randValue()],
169
                    [9, 26 + randValue()],
170
                    [10, 38 + randValue()],
171
                    [11, 39 + randValue()],
172
                    [12, 50 + randValue()],
173
                    [13, 51 + randValue()],
174
                    [14, 12 + randValue()],
175
                    [15, 13 + randValue()],
176
                    [16, 14 + randValue()],
177
                    [17, 15 + randValue()],
178
                    [18, 15 + randValue()],
179
                    [19, 16 + randValue()],
180
                    [20, 17 + randValue()],
181
                    [21, 18 + randValue()],
182
                    [22, 19 + randValue()],
183
                    [23, 20 + randValue()],
184
                    [24, 21 + randValue()],
185
                    [25, 14 + randValue()],
186
                    [26, 24 + randValue()],
187
                    [27, 25 + randValue()],
188
                    [28, 26 + randValue()],
189
                    [29, 27 + randValue()],
190
                    [30, 31 + randValue()]
191
                ];
192
 
193
                var plot = $.plot($("#chart_2"), [{
194
                    data: pageviews,
195
                    label: "Unique Visits",
196
                    lines: {
197
                        lineWidth: 1,
198
                    },
199
                    shadowSize: 0
200
 
201
                }, {
202
                    data: visitors,
203
                    label: "Page Views",
204
                    lines: {
205
                        lineWidth: 1,
206
                    },
207
                    shadowSize: 0
208
                }], {
209
                    series: {
210
                        lines: {
211
                            show: true,
212
                            lineWidth: 2,
213
                            fill: true,
214
                            fillColor: {
215
                                colors: [{
216
                                    opacity: 0.05
217
                                }, {
218
                                    opacity: 0.01
219
                                }]
220
                            }
221
                        },
222
                        points: {
223
                            show: true,
224
                            radius: 3,
225
                            lineWidth: 1
226
                        },
227
                        shadowSize: 2
228
                    },
229
                    grid: {
230
                        hoverable: true,
231
                        clickable: true,
232
                        tickColor: "#eee",
233
                        borderColor: "#eee",
234
                        borderWidth: 1
235
                    },
236
                    colors: ["#d12610", "#37b7f3", "#52e136"],
237
                    xaxis: {
238
                        ticks: 11,
239
                        tickDecimals: 0,
240
                        tickColor: "#eee",
241
                    },
242
                    yaxis: {
243
                        ticks: 11,
244
                        tickDecimals: 0,
245
                        tickColor: "#eee",
246
                    }
247
                });
248
 
249
 
250
                function showTooltip(x, y, contents) {
251
                    $('<div id="tooltip">' + contents + '</div>').css({
252
                        position: 'absolute',
253
                        display: 'none',
254
                        top: y + 5,
255
                        left: x + 15,
256
                        border: '1px solid #333',
257
                        padding: '4px',
258
                        color: '#fff',
259
                        'border-radius': '3px',
260
                        'background-color': '#333',
261
                        opacity: 0.80
262
                    }).appendTo("body").fadeIn(200);
263
                }
264
 
265
                var previousPoint = null;
266
                $("#chart_2").bind("plothover", function(event, pos, item) {
267
                    $("#x").text(pos.x.toFixed(2));
268
                    $("#y").text(pos.y.toFixed(2));
269
 
270
                    if (item) {
271
                        if (previousPoint != item.dataIndex) {
272
                            previousPoint = item.dataIndex;
273
 
274
                            $("#tooltip").remove();
275
                            var x = item.datapoint[0].toFixed(2),
276
                                y = item.datapoint[1].toFixed(2);
277
 
278
                            showTooltip(item.pageX, item.pageY, item.series.label + " of " + x + " = " + y);
279
                        }
280
                    } else {
281
                        $("#tooltip").remove();
282
                        previousPoint = null;
283
                    }
284
                });
285
            }
286
 
287
            //Tracking Curves
288
 
289
            function chart3() {
290
                if ($('#chart_3').size() != 1) {
291
                    return;
292
                }
293
                //tracking curves:
294
 
295
                var sin = [],
296
                    cos = [];
297
                for (var i = 0; i < 14; i += 0.1) {
298
                    sin.push([i, Math.sin(i)]);
299
                    cos.push([i, Math.cos(i)]);
300
                }
301
 
302
                plot = $.plot($("#chart_3"), [{
303
                    data: sin,
304
                    label: "sin(x) = -0.00",
305
                    lines: {
306
                        lineWidth: 1,
307
                    },
308
                    shadowSize: 0
309
                }, {
310
                    data: cos,
311
                    label: "cos(x) = -0.00",
312
                    lines: {
313
                        lineWidth: 1,
314
                    },
315
                    shadowSize: 0
316
                }], {
317
                    series: {
318
                        lines: {
319
                            show: true
320
                        }
321
                    },
322
                    crosshair: {
323
                        mode: "x"
324
                    },
325
                    grid: {
326
                        hoverable: true,
327
                        autoHighlight: false,
328
                        tickColor: "#eee",
329
                        borderColor: "#eee",
330
                        borderWidth: 1
331
                    },
332
                    yaxis: {
333
                        min: -1.2,
334
                        max: 1.2
335
                    }
336
                });
337
 
338
                var legends = $("#chart_3 .legendLabel");
339
                legends.each(function() {
340
                    // fix the widths so they don't jump around
341
                    $(this).css('width', $(this).width());
342
                });
343
 
344
                var updateLegendTimeout = null;
345
                var latestPosition = null;
346
 
347
                function updateLegend() {
348
                    updateLegendTimeout = null;
349
 
350
                    var pos = latestPosition;
351
 
352
                    var axes = plot.getAxes();
353
                    if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max || pos.y < axes.yaxis.min || pos.y > axes.yaxis.max) return;
354
 
355
                    var i, j, dataset = plot.getData();
356
                    for (i = 0; i < dataset.length; ++i) {
357
                        var series = dataset[i];
358
 
359
                        // find the nearest points, x-wise
360
                        for (j = 0; j < series.data.length; ++j)
361
                            if (series.data[j][0] > pos.x) break;
362
 
363
                            // now interpolate
364
                        var y, p1 = series.data[j - 1],
365
                            p2 = series.data[j];
366
 
367
                        if (p1 == null) y = p2[1];
368
                        else if (p2 == null) y = p1[1];
369
                        else y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);
370
 
371
                        legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));
372
                    }
373
                }
374
 
375
                $("#chart_3").bind("plothover", function(event, pos, item) {
376
                    latestPosition = pos;
377
                    if (!updateLegendTimeout) updateLegendTimeout = setTimeout(updateLegend, 50);
378
                });
379
            }
380
 
381
            //Dynamic Chart
382
 
383
            function chart4() {
384
                if ($('#chart_4').size() != 1) {
385
                    return;
386
                }
387
                //server load
388
                var options = {
389
                    series: {
390
                        shadowSize: 1
391
                    },
392
                    lines: {
393
                        show: true,
394
                        lineWidth: 0.5,
395
                        fill: true,
396
                        fillColor: {
397
                            colors: [{
398
                                opacity: 0.1
399
                            }, {
400
                                opacity: 1
401
                            }]
402
                        }
403
                    },
404
                    yaxis: {
405
                        min: 0,
406
                        max: 100,
407
                        tickColor: "#eee",
408
                        tickFormatter: function(v) {
409
                            return v + "%";
410
                        }
411
                    },
412
                    xaxis: {
413
                        show: false,
414
                    },
415
                    colors: ["#6ef146"],
416
                    grid: {
417
                        tickColor: "#eee",
418
                        borderWidth: 0,
419
                    }
420
                };
421
 
422
                var updateInterval = 30;
423
                var plot = $.plot($("#chart_4"), [getRandomData()], options);
424
 
425
                function update() {
426
                    plot.setData([getRandomData()]);
427
                    plot.draw();
428
                    setTimeout(update, updateInterval);
429
                }
430
                update();
431
            }
432
 
433
            //bars with controls
434
 
435
            function chart5() {
436
                if ($('#chart_5').size() != 1) {
437
                    return;
438
                }
439
                var d1 = [];
440
                for (var i = 0; i <= 10; i += 1)
441
                    d1.push([i, parseInt(Math.random() * 30)]);
442
 
443
                var d2 = [];
444
                for (var i = 0; i <= 10; i += 1)
445
                    d2.push([i, parseInt(Math.random() * 30)]);
446
 
447
                var d3 = [];
448
                for (var i = 0; i <= 10; i += 1)
449
                    d3.push([i, parseInt(Math.random() * 30)]);
450
 
451
                var stack = 0,
452
                    bars = true,
453
                    lines = false,
454
                    steps = false;
455
 
456
                function plotWithOptions() {
457
                    $.plot($("#chart_5"),
458
 
459
                        [{
460
                            label: "sales",
461
                            data: d1,
462
                            lines: {
463
                                lineWidth: 1,
464
                            },
465
                            shadowSize: 0
466
                        }, {
467
                            label: "tax",
468
                            data: d2,
469
                            lines: {
470
                                lineWidth: 1,
471
                            },
472
                            shadowSize: 0
473
                        }, {
474
                            label: "profit",
475
                            data: d3,
476
                            lines: {
477
                                lineWidth: 1,
478
                            },
479
                            shadowSize: 0
480
                        }]
481
 
482
                        , {
483
                            series: {
484
                                stack: stack,
485
                                lines: {
486
                                    show: lines,
487
                                    fill: true,
488
                                    steps: steps,
489
                                    lineWidth: 0, // in pixels
490
                                },
491
                                bars: {
492
                                    show: bars,
493
                                    barWidth: 0.5,
494
                                    lineWidth: 0, // in pixels
495
                                    shadowSize: 0,
496
                                    align: 'center'
497
                                }
498
                            },
499
                            grid: {
500
                                tickColor: "#eee",
501
                                borderColor: "#eee",
502
                                borderWidth: 1
503
                            }
504
                        }
505
                    );
506
                }
507
 
508
                $(".stackControls input").click(function(e) {
509
                    e.preventDefault();
510
                    stack = $(this).val() == "With stacking" ? true : null;
511
                    plotWithOptions();
512
                });
513
 
514
                $(".graphControls input").click(function(e) {
515
                    e.preventDefault();
516
                    bars = $(this).val().indexOf("Bars") != -1;
517
                    lines = $(this).val().indexOf("Lines") != -1;
518
                    steps = $(this).val().indexOf("steps") != -1;
519
                    plotWithOptions();
520
                });
521
 
522
                plotWithOptions();
523
            }
524
 
525
            //graph
526
            chart1();
527
            chart2();
528
            chart3();
529
            chart4();
530
            chart5();
531
 
532
        },
533
 
534
        initBarCharts: function() {
535
 
536
            // bar chart:
537
            var data = GenerateSeries(0);
538
 
539
            function GenerateSeries(added) {
540
                var data = [];
541
                var start = 100 + added;
542
                var end = 200 + added;
543
 
544
                for (i = 1; i <= 20; i++) {
545
                    var d = Math.floor(Math.random() * (end - start + 1) + start);
546
                    data.push([i, d]);
547
                    start++;
548
                    end++;
549
                }
550
 
551
                return data;
552
            }
553
 
554
            var options = {
555
                series: {
556
                    bars: {
557
                        show: true
558
                    }
559
                },
560
                bars: {
561
                    barWidth: 0.8,
562
                    lineWidth: 0, // in pixels
563
                    shadowSize: 0,
564
                    align: 'left'
565
                },
566
 
567
                grid: {
568
                    tickColor: "#eee",
569
                    borderColor: "#eee",
570
                    borderWidth: 1
571
                }
572
            };
573
 
574
            if ($('#chart_1_1').size() !== 0) {
575
                $.plot($("#chart_1_1"), [{
576
                    data: data,
577
                    lines: {
578
                        lineWidth: 1,
579
                    },
580
                    shadowSize: 0
581
                }], options);
582
            }
583
 
584
            // horizontal bar chart:
585
 
586
            var data1 = [
587
                [10, 10],
588
                [20, 20],
589
                [30, 30],
590
                [40, 40],
591
                [50, 50]
592
            ];
593
 
594
            var options = {
595
                series: {
596
                    bars: {
597
                        show: true
598
                    }
599
                },
600
                bars: {
601
                    horizontal: true,
602
                    barWidth: 6,
603
                    lineWidth: 0, // in pixels
604
                    shadowSize: 0,
605
                    align: 'left'
606
                },
607
                grid: {
608
                    tickColor: "#eee",
609
                    borderColor: "#eee",
610
                    borderWidth: 1
611
                }
612
            };
613
 
614
            if ($('#chart_1_2').size() !== 0) {
615
                $.plot($("#chart_1_2"), [data1], options);
616
            }
617
        },
618
 
619
        initPieCharts: function() {
620
 
621
            var data = [];
622
            var series = Math.floor(Math.random() * 10) + 1;
623
            series = series < 5 ? 5 : series;
624
 
625
            for (var i = 0; i < series; i++) {
626
                data[i] = {
627
                    label: "Series" + (i + 1),
628
                    data: Math.floor(Math.random() * 100) + 1
629
                };
630
            }
631
 
632
            // DEFAULT
633
            if ($('#pie_chart').size() !== 0) {
634
                $.plot($("#pie_chart"), data, {
635
                    series: {
636
                        pie: {
637
                            show: true
638
                        }
639
                    }
640
                });
641
            }
642
 
643
            // GRAPH 1
644
            if ($('#pie_chart_1').size() !== 0) {
645
                $.plot($("#pie_chart_1"), data, {
646
                    series: {
647
                        pie: {
648
                            show: true
649
                        }
650
                    },
651
                    legend: {
652
                        show: false
653
                    }
654
                });
655
            }
656
 
657
            // GRAPH 2
658
            if ($('#pie_chart_2').size() !== 0) {
659
                $.plot($("#pie_chart_2"), data, {
660
                    series: {
661
                        pie: {
662
                            show: true,
663
                            radius: 1,
664
                            label: {
665
                                show: true,
666
                                radius: 1,
667
                                formatter: function(label, series) {
668
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
669
                                },
670
                                background: {
671
                                    opacity: 0.8
672
                                }
673
                            }
674
                        }
675
                    },
676
                    legend: {
677
                        show: false
678
                    }
679
                });
680
            }
681
 
682
            // GRAPH 3
683
            if ($('#pie_chart_3').size() !== 0) {
684
                $.plot($("#pie_chart_3"), data, {
685
                    series: {
686
                        pie: {
687
                            show: true,
688
                            radius: 1,
689
                            label: {
690
                                show: true,
691
                                radius: 3 / 4,
692
                                formatter: function(label, series) {
693
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
694
                                },
695
                                background: {
696
                                    opacity: 0.5
697
                                }
698
                            }
699
                        }
700
                    },
701
                    legend: {
702
                        show: false
703
                    }
704
                });
705
            }
706
 
707
            // GRAPH 4
708
            if ($('#pie_chart_4').size() !== 0) {
709
                $.plot($("#pie_chart_4"), data, {
710
                    series: {
711
                        pie: {
712
                            show: true,
713
                            radius: 1,
714
                            label: {
715
                                show: true,
716
                                radius: 3 / 4,
717
                                formatter: function(label, series) {
718
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
719
                                },
720
                                background: {
721
                                    opacity: 0.5,
722
                                    color: '#000'
723
                                }
724
                            }
725
                        }
726
                    },
727
                    legend: {
728
                        show: false
729
                    }
730
                });
731
            }
732
 
733
            // GRAPH 5
734
            if ($('#pie_chart_5').size() !== 0) {
735
                $.plot($("#pie_chart_5"), data, {
736
                    series: {
737
                        pie: {
738
                            show: true,
739
                            radius: 3 / 4,
740
                            label: {
741
                                show: true,
742
                                radius: 3 / 4,
743
                                formatter: function(label, series) {
744
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
745
                                },
746
                                background: {
747
                                    opacity: 0.5,
748
                                    color: '#000'
749
                                }
750
                            }
751
                        }
752
                    },
753
                    legend: {
754
                        show: false
755
                    }
756
                });
757
            }
758
 
759
            // GRAPH 6
760
            if ($('#pie_chart_6').size() !== 0) {
761
                $.plot($("#pie_chart_6"), data, {
762
                    series: {
763
                        pie: {
764
                            show: true,
765
                            radius: 1,
766
                            label: {
767
                                show: true,
768
                                radius: 2 / 3,
769
                                formatter: function(label, series) {
770
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
771
                                },
772
                                threshold: 0.1
773
                            }
774
                        }
775
                    },
776
                    legend: {
777
                        show: false
778
                    }
779
                });
780
            }
781
 
782
            // GRAPH 7
783
            if ($('#pie_chart_7').size() !== 0) {
784
                $.plot($("#pie_chart_7"), data, {
785
                    series: {
786
                        pie: {
787
                            show: true,
788
                            combine: {
789
                                color: '#999',
790
                                threshold: 0.1
791
                            }
792
                        }
793
                    },
794
                    legend: {
795
                        show: false
796
                    }
797
                });
798
            }
799
 
800
            // GRAPH 8
801
            if ($('#pie_chart_8').size() !== 0) {
802
                $.plot($("#pie_chart_8"), data, {
803
                    series: {
804
                        pie: {
805
                            show: true,
806
                            radius: 300,
807
                            label: {
808
                                show: true,
809
                                formatter: function(label, series) {
810
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
811
                                },
812
                                threshold: 0.1
813
                            }
814
                        }
815
                    },
816
                    legend: {
817
                        show: false
818
                    }
819
                });
820
            }
821
 
822
            // GRAPH 9
823
            if ($('#pie_chart_9').size() !== 0) {
824
                $.plot($("#pie_chart_9"), data, {
825
                    series: {
826
                        pie: {
827
                            show: true,
828
                            radius: 1,
829
                            tilt: 0.5,
830
                            label: {
831
                                show: true,
832
                                radius: 1,
833
                                formatter: function(label, series) {
834
                                    return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
835
                                },
836
                                background: {
837
                                    opacity: 0.8
838
                                }
839
                            },
840
                            combine: {
841
                                color: '#999',
842
                                threshold: 0.1
843
                            }
844
                        }
845
                    },
846
                    legend: {
847
                        show: false
848
                    }
849
                });
850
            }
851
 
852
            // DONUT
853
            if ($('#donut').size() !== 0) {
854
                $.plot($("#donut"), data, {
855
                    series: {
856
                        pie: {
857
                            innerRadius: 0.5,
858
                            show: true
859
                        }
860
                    }
861
                });
862
            }
863
 
864
            // INTERACTIVE
865
            if ($('#interactive').size() !== 0) {
866
                $.plot($("#interactive"), data, {
867
                    series: {
868
                        pie: {
869
                            show: true
870
                        }
871
                    },
872
                    grid: {
873
                        hoverable: true,
874
                        clickable: true
875
                    }
876
                });
877
                $("#interactive").bind("plothover", pieHover);
878
                $("#interactive").bind("plotclick", pieClick);
879
            }
880
 
881
            function pieHover(event, pos, obj) {
882
                if (!obj)
883
                    return;
884
                percent = parseFloat(obj.series.percent).toFixed(2);
885
                $("#hover").html('<span style="font-weight: bold; color: ' + obj.series.color + '">' + obj.series.label + ' (' + percent + '%)</span>');
886
            }
887
 
888
            function pieClick(event, pos, obj) {
889
                if (!obj)
890
                    return;
891
                percent = parseFloat(obj.series.percent).toFixed(2);
892
                alert('' + obj.series.label + ': ' + percent + '%');
893
            }
894
 
895
        }
896
 
897
    };
898
 
899
}();