summaryrefslogtreecommitdiff
path: root/schall/static/RGraph/docs/basic_tooltips.html
blob: c3d591c625f2d33cb59daba4c3ebfdba330002ec (plain)
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
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <!--
        /**
        * o------------------------------------------------------------------------------o
        * | This file is part of the RGraph package - you can learn more at:             |
        * |                                                                              |
        * |                          http://www.rgraph.net                               |
        * |                                                                              |
        * | This package is licensed under the RGraph license. For all kinds of business |
        * | purposes there is a small one-time licensing fee to pay and for non          |
        * | commercial  purposes it is free to use. You can read the full license here:  |
        * |                                                                              |
        * |                      http://www.rgraph.net/LICENSE.txt                       |
        * o------------------------------------------------------------------------------o
        */
    -->

    <title>RGraph: HTML5 Javascript charts library - A basic example of Pie charts in tooltips</title>
    
    <meta name="keywords" content="rgraph javascript charts html5 canvas basic example pie charts tooltips" />
    <meta name="description" content="RGraph: HTML5 Javascript charts library -  A basic example of Pie charts in tooltips" />

    <!-- Include the RGraph libraries -->
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.tooltips.js" ></script>
    <script src="../libraries/RGraph.bar.js" ></script>
    <script src="../libraries/RGraph.pie.js" ></script>
    <!--[if IE 8]><script src="../excanvas/excanvas.original.js"></script><![endif]-->

</head>

<body>

    <h1>RGraph: <span>HTML5 Javascript charts library</span> - A basic example of Pie charts in tooltips</h1>

    <canvas id="myBar" width="1000" height="250">[No canvas support]</canvas>

    <script>
        window.onload = function ()
        {
            /**
            * This creates the Bar chart
            */
            var bar = new RGraph.Bar('myBar', [12,13,16,15]);
            bar.Set('chart.gutter.left', 35);
            bar.Set('chart.colors', ['red']);
            bar.Set('chart.title', 'A basic graph with charts in tooltips');
            bar.Set('chart.labels', ['Kev', 'Brian', 'Fred', 'John']);

            // A function which returns the string which is used as every tooltip
            bar.Set('chart.tooltips', function () { return '<canvas id="__tooltip__canvas__" width="300" height="200">[No canvas support]</canvas>';});

            bar.Draw();


            /**
            * This is the function which ceates the Pie chart (using the custom ontooltip RGraph event
            */
            function myCreatePieChart(obj)
            {
                var canvas  = obj.canvas;
                var context = obj.context;
                var id      = obj.id;
                
                // This gets the tooltip index from the tooltip (which is stored in the RGraph registry) itself
                var idx = RGraph.Registry.Get('chart.tooltip').__index__;
                
                /**
                * The Pie chart data. Realistically this would come from a dynamic source,
                * eg AJAX
                */
                var pieData = [
                               [4,5,3,6],
                               [8,4,5,2],
                               [4,3,5,1],
                               [4,2,1,3]
                              ];
                
                var pie = new RGraph.Pie('__tooltip__canvas__', pieData[idx]);
                pie.Set('chart.key', ['Monday','Tuesday','Wednesday','Thursday']);
                pie.Set('chart.align', 'left');
                pie.Set('chart.gutter.top', 10);
                pie.Set('chart.gutter.bottom', 10);
                pie.Set('chart.gutter.left', 10);
                pie.Set('chart.gutter.right', 10);
                pie.Set('chart.exploded', [3,3,3,3]);
                pie.Set('chart.strokestyle', 'rgba(0,0,0,0)');
                pie.Draw();
            }

            RGraph.AddCustomEventListener(bar, 'ontooltip', myCreatePieChart);
        }
    </script>
    
    <p>
        This is a basic example that shows charts (Pie charts) in tooltips. The canvas element is part of the tooltip
        HTML code (specified like regular tooltips), and then it uses the <i>ontooltip</i> event to run some code whhich
        then creates the Pie chart in the tooltip.
    </p>

</body>
</html>