1 <?php ob_start('ob_gzhandler') ?>
5 <meta http-equiv="X-UA-Compatible" content="chrome=1">
8 * o------------------------------------------------------------------------------o
9 * | This file is part of the RGraph package - you can learn more at: |
11 * | http://www.rgraph.net |
13 * | This package is licensed under the RGraph license. For all kinds of business |
14 * | purposes there is a small one-time licensing fee to pay and for non |
15 * | commercial purposes it is free to use. You can read the full license here: |
17 * | http://www.rgraph.net/LICENSE.txt |
18 * o------------------------------------------------------------------------------o
21 <title>RGraph: HTML5 canvas graph library - Integrating RGraph with external libraries</title>
23 <meta name="keywords" content="rgraph html5 canvas graph docs external libraries" />
24 <meta name="description" content="RGraph: HTML5 canvas graph software - Documentation about integrating RGraph with external libraries" />
26 <link rel="stylesheet" href="../css/website.css" type="text/css" media="screen" />
27 <link rel="stylesheet" href="../css/ModalDialog.css" type="text/css" media="screen" />
28 <link rel="icon" type="image/png" href="../images/favicon.png">
30 <script src="../libraries/RGraph.modaldialog.js" ></script>
31 <script src="../libraries/RGraph.common.core.js" ></script>
32 <script src="../libraries/RGraph.common.context.js" ></script>
33 <script src="../libraries/RGraph.line.js" ></script>
34 <!--[if IE 8]><script src="../excanvas/excanvas.compressed.js"></script><![endif]-->
37 window.onload = function ()
42 var line = new RGraph.Line('myLine', [45,12,16,18,44,54,23,21,56,58,33,47]);
43 line.Set('chart.background.barcolor1', 'white');
44 line.Set('chart.background.barcolor2', 'white');
45 line.Set('chart.tickmarks', null);
46 line.Set('chart.hmargin', 10);
47 line.Set('chart.linewidth', 3);
48 line.Set('chart.shadow', true);
49 line.Set('chart.shadow.offset', 2);
50 line.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
51 line.Set('chart.title', 'A line graph with context menu');
53 // This defines a context menu which shows the dialog. The commented out
54 // bit defines an onclick handler on the background, so that when you
55 // click it (the background), the dialog is hidden.
56 line.Set('chart.contextmenu', [
57 ['Login to admin area...', function () {ModalDialog.Show('myDialog', 300);/*ModalDialog.background.onclick = function () {ModalDialog.Close();};*/}],
59 ['Cancel', function () {}]
69 * These are the CSS classes that you can use to customise the appearance of the ModalDialog. If you're trying to
70 * override something which the scripts set, then because of the ordering you may need to use the "! important"
73 .ModalDialog_background {
77 -webkit-box-shadow: gray 0 0 15px ! important;
78 -moz-box-shadow: 0 0 15px gray ! important;
79 box-shadow: 0 0 15px gray ! important;
89 <!-- Social networking buttons -->
90 <script src="../libraries/RGraph.common.core.js" ></script>
93 function HideTwitterDIV ()
95 document.getElementById("twitter_div").style.opacity = 0;
96 document.getElementById("twitter_div").style.display = 'none';
100 function ShowTwitterDIV (e)
102 var e = RGraph.FixEventObject(document.all ? event : e);
103 var div = document.getElementById("twitter_div");
104 var img = document.getElementById("twitter_icon");
106 div.style.display = 'block';
107 div.style.left = (RGraph.getCanvasXY(img)[0] + img.offsetWidth - div.offsetWidth + 110) + 'px';
108 div.style.top = (RGraph.getCanvasXY(img)[1] - 1) + 'px';
113 setTimeout('document.getElementById("twitter_div").style.opacity = 0.2;', 25);
114 setTimeout('document.getElementById("twitter_div").style.opacity = 0.4;', 50);
115 setTimeout('document.getElementById("twitter_div").style.opacity = 0.6;', 100);
116 setTimeout('document.getElementById("twitter_div").style.opacity = 0.8;', 125);
117 setTimeout('document.getElementById("twitter_div").style.opacity = 1.0;', 150);
125 * This code installs the event handler that hides the Twitter DIV
127 if (RGraph.isIE8()) {
128 window.attachEvent('onload', function () {document.body.attachEvent('onclick', HideTwitterDIV);});
130 window.addEventListener('click', HideTwitterDIV, false);
134 <!-- The twitter DIV -->
135 <div id="twitter_div" style="position: absolute;top: 0;left: 0;background-color: #eee;border: 2px dashed black;box-shadow: 0 0 15px #aaa;-moz-box-shadow: 0 0 15px #aaa;-webkit-box-shadow: 0 0 15px #aaa;padding: 3px;display: none;opacity: 0;z-index: 99;">
136 <a href="http://twitter.com/home/?status=RGraph%3A+HTML5+canvas+graph+library+based+on+the+HTML5+canvas+tag+http%3A%2F%2Fwww.rgraph.net+%23rgraph+%23html5+%23canvas" target="_blank" title="Share on Twitter" rel="nofollow" style="text-decoration: none">Tweet about RGraph</a><br>
137 <a href="http://twitter.com/_rgraph" style="text-decoration: none" rel="nofollow" target="_blank">Follow for HTML5 news</a>
140 <div id="social_icons" class="warning" style="top: 0; left: 5px; position: absolute">
143 if (navigator.userAgent.indexOf('Opera') == -1) {
144 document.getElementById("social_icons").style.position = 'fixed';
145 document.getElementById("twitter_div").style.position = 'fixed';
150 <b style="display: inline-block; position: relative; top: 1px">Bookmark and share:</b>
154 <a title="Bookmark with delicious" href="http://delicious.com/save?jump=close&v=4&noui&jump=close&url=http://www.rgraph.net¬es=RGraph%20is%20a%20HTML5%20based%20graph%20library%20supporting%20a%20wide%20range%20of%20different%20graph%20types:Bar,%20Bipolar,%20Donut,%20Funnel,%20Gantt,%20Horizontal%20Bar,%20LED,%20Line,%20Meter,%20Odometer,%20Pie,%20Progress%20Bar,%20Rose,%20RScatter,%20Scatter%20and%20Traditional%20Radar&title=RGraph:%20HTML5%20canvas%20graph%20library%20based%20on%20the%20HTML5%20canvas%20tag" target="_blank">
155 <img src="../images/delicious.png" alt="Bookmark with delicious" width="22" height="22" border="0" align="absmiddle" />
158 <a href="" target="_blank" onmouseover="if (document.getElementById('twitter_div').style.display == 'none') ShowTwitterDIV(event);" onclick="event.stopPropagation(); event.cancelBubble = true; return false">
159 <img src="../images/twitter.png" id="twitter_icon" alt="tweet this site" width="22" height="22" border="0" align="absmiddle" />
164 <a title="Post to Google Buzz!" href="" onclick="window.open('http://www.google.com/buzz/post?url=http://www.rgraph.net&imageurl=http://www.rgraph.net/images/logo.png', 'google_buzz_window', 'width=800,height=400,top=100,left=100'); return false">
165 <img src="../images/buzz.png" width="22" height="22" alt="Post to Google Buzz!" align="absmiddle" style="position: relative; top: -2px; border: 0" border="0"/>
169 <a title="Share RGraph on Facebook" href="" onclick="window.open('http://www.facebook.com/sharer.php?u=http://www.rgraph.net&t=RGraph:%20HTML5%20canvas%20graph%20library', 'facebook_window', 'width=500,height=300,top=100,left=100'); return false">
170 <img src="../images/facebook.png" width="22" height="22" alt="Post to Facebook" align="absmiddle" style="position: relative; top: -2px; border: 0" border="0"/>
173 <a href="mailto:share@friendfeed.com" title="Share on FriendFeed">
174 <img src="../images/friendfeed.png" width="22" height="22" alt="Share on FriendFeed" border="0" align="absmiddle" />
177 <a href="http://www.stumbleupon.com/submit?url=http://www.rgraph.net" target="_blank" title="Share on StumbleUpon" >
178 <img src="../images/stumble.png" alt="Stumble! this site" width="22" height="22" border="0" align="absmiddle" />
183 <!-- /Social networking buttons -->
186 <div id="breadcrumb">
187 <a href="../index.html">RGraph: HTML5 canvas graph library</a>
189 <a href="index.html">Documentation</a>
191 Integrating RGraph with external libraries
194 <h1>RGraph: HTML5 canvas graph library - Integrating RGraph with external libraries</h1>
197 if (RGraph.isIE8()) {
198 document.write('<div style="background-color: #fee; border: 2px dashed red; padding: 5px"><b>Important</b><br /><br /> Internet Explorer 8 does not natively support the HTML5 canvas tag, so if you want to see the graphs, you can either:<ul><li>Install <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a></li><li>Use ExCanvas. This is provided in the RGraph Archive.</li><li>Use another browser entirely. Your choices are Firefox 3.5+, Chrome 2+, Safari 4+ or Opera 10.5+. </li></ul> <b>Note:</b> Internet Explorer 9 fully supports the canvas tag. Click <a href="http://groups.google.com/group/rgraph/browse_thread/thread/c5651ff8c56b8f3c#" target="_blank">here</a> to see some screenshots.</div>');
203 <li><a href="#msie">Note about Microsoft Internet Explorer and the ModalDialog</a></li>
204 <li><a href="#hiding">Hiding the ModalDialog</a></li>
205 <li><a href="#customising">Customising the ModalDialog</a></li>
206 <li><a href="#integration">ModalDialog integration</a></li>
209 <canvas id="myLine" width="400" height="200" style="float: right">[No canvas support]</canvas>
212 This page shows you how you can easily integrate the graphs with other external Javascript libraries. This particular example
213 attaches a context menu to the graph, of which the only option is to show a login dialog. This could, for example, be used to
214 allow logging in to an admin area.
218 The dialog doesn't need to require user input - it could just be a static "Please wait..." type dialog, which is shown while a
219 subsequent page loads that takes a few seconds.
223 The ModalDialog was originally an external library, however it's now part of the RGraph package. It's also covered by the
224 RGraph license - so if you have an <a href="licensing.html">RGraph license</a>, then the ModalDialog is part of that.
230 <script src="RGraph.common.core.js">
231 <script src="RGraph.common.context.js">
232 <script src="RGraph.line.js">
233 <script src="RGraph.modaldialog.js">
236 window.onload = function ()
239 * Draw the line graph
241 var line = new RGraph.Line('myLine', [45,12,16,18,44,54,23,21,56,58,33,47]);
242 line.Set('chart.background.barcolor1', 'white');
243 line.Set('chart.background.barcolor2', 'white');
244 line.Set('chart.tickmarks', null);
245 line.Set('chart.hmargin', 10);
246 line.Set('chart.linewidth', 3);
247 line.Set('chart.shadow', true);
248 line.Set('chart.shadow.offset', 2);
249 line.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
250 line.Set('chart.title', 'A line graph with context menu');
251 <span style="color: green">
252 // This defines a context menu which calls the given function. This function in turn shows the dialog
253 line.Set('chart.contextmenu', [['Login to admin area...', function () {ModalDialog.Show('myDialog', 300);}}]]);
257 </script></pre>
260 If you're interested in using this modal dialog, then you'll probably also want the CSS that styles it. This can be found in the
261 "css" directory.
265 <h3>Note about Microsoft Internet Explorer 8 and the ModalDialog</h3>
268 Microsoft Internet Explorer 8 only supports fixed positioning in strict rendering mode, therefore you must specify a DTD
269 when using this browser. Eg:
273 <!DOCTYPE html >
276 <a name="hiding"></a>
277 <h3>Hiding the ModalDialog</h3>
279 To hide the ModalDialog (from a "Cancel" button for example), you can use the Close() method:
283 <input type="reset" value="Cancel" onclick="ModalDialog.Close()">
286 <a name="customising"></a>
287 <h3>Customising the ModalDialog</h3>
289 You can customise the appearance of the ModalDialog by using three CSS classes, which are documented <a href="css.html">here</a>.
290 This page customises the dialog slightly by changing the shadow X/Y offsets:
296 * These are the CSS classes that you can use to customise the appearance of the ModalDialog. If you're trying to
297 * override something which the scripts set, then because of the ordering you may need to use the "! important"
302 * This is the semi-opaque background
304 .ModalDialog_background {
309 * This is the dialog itself
311 .ModalDialog_dialog {
312 -webkit-box-shadow: gray 0 0 15px ! important;
313 -moz-box-shadow: 0 0 15px gray ! important;
314 box-shadow: 0 0 15px gray ! important;
319 * This is gray bar at the top of the dialog
321 .ModalDialog_topbar {
326 <a name="integration"></a>
327 <h3>ModalDialog integration</h3>
329 To integrate the ModalDialog look at the sample code above (the key line is where the context menu is defined). The method you should call is <b>ModalDialog.Show(id, width)</b>.
330 The <i>id</i> is the <i>id</i> of the layer to use. Only the <i>.innerHTML</i> is used, not the layer itself, so it can be hidden by
331 setting the display CSS <i>display</i> property to <i>none</i>. The <i>width</i> is a number which is used as the width of the dialog.
335 The only library needed for the ModalDialog to work is <i>RGraph.modaldialog.js</i> - you do not need to use
336 <i>RGraph.common.js</i>. This makes for far smaller download requirements.
340 <!-- This is the popup dialog-->
342 <div id="myDialog" class="modalDialog" style="display: none">
348 <td align="right" style="padding-top: 4px">Email</td>
349 <td><input type="text" size="20" name="email" style="width: 150px" /></td>
353 <td align="right" style="padding-top: 4px">Password</td>
354 <td><input type="password" size="20" name="password" style="width: 150px" /></td>
358 <td colspan="2" align="right">
359 <input type="reset" value="Cancel" onclick="ModalDialog.Close()">
360 <input type="submit" name="submit" value="Login »" onclick="alert('This is just an example'); if (document.all) event.cancelBubble = true; else event.stopPropagation()">
367 <!-- End of dialog -->