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
|
<!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 - combining bar and line charts</title>
<meta name="keywords" content="rgraph html5 canvas chart docs combining" />
<meta name="description" content="RGraph: HTML5 Javascript charts library - Documentation about combining charts" />
<meta property="og:title" content="RGraph: HTML5 Javascript charts library" />
<meta property="og:description" content="A chart library based on the HTML5 canvas tag" />
<meta property="og:image" content="http://www.rgraph.net/images/logo.png"/>
<link rel="stylesheet" href="../css/website.css" type="text/css" media="screen" />
<link rel="icon" type="image/png" href="../images/favicon.png">
<!-- Place this tag in your head or just before your close body tag -->
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script src="../libraries/RGraph.common.core.js" ></script>
<script src="../libraries/RGraph.common.context.js" ></script>
<script src="../libraries/RGraph.common.tooltips.js" ></script>
<script src="../libraries/RGraph.common.effects.js" ></script>
<script src="../libraries/RGraph.bar.js" ></script>
<script src="../libraries/RGraph.line.js" ></script>
<script src="../libraries/RGraph.pie.js" ></script>
<!--[if IE 8]><script src="../excanvas/excanvas.original.js"></script><![endif]-->
<style>
div.RGraph_tooltip div {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
}
div.RGraph_tooltip div#green {
background-color: green;
}
div.RGraph_tooltip div#red {
background-color: red;
}
div.RGraph_tooltip div#gray {
background-color: #ccc;
}
</style>
<script>
function enlarge_tooltip_graph (e, title)
{
var bg = document.createElement('DIV');
bg.style.opacity = 0;
bg.style.position = 'fixed';
bg.style.left = 0;
bg.style.top = 0;
bg.style.width = '2000px';
bg.style.height = '2000px';
bg.style.backgroundColor = 'rgba(0,0,0,0.2)';
bg.style.zIndex = 32568;
bg.style.textAlign = 'center';
document.body.appendChild(bg);
var div = document.createElement('DIV');
div.style.position = 'relative';
div.style.backgroundColor = 'white';
div.style.top = '200px';
div.style.width = '300px'
div.style.height = '240px';
div.style.padding = '15px';
div.style.WebkitBorderRadius = '5px';
div.style.MozBorderRadius = '5px';
div.style.borderRadius = '5px';
div.style.left = ((document.body.clientWidth / 2) - 175) + 'px';
// Add standard box-shadow and -moz-box-shadow
div.style.WebkitBoxShadow = 'gray 0 0 25px';
div.style.MozBoxShadow = '0 0 25px gray';
div.style.boxShadow = '0 0 25px gray';
div.style.border = '1px black solid';
bg.appendChild(div);
var canvas = document.createElement('CANVAS');
canvas.width = 300;
canvas.height = 240;
canvas.id = 'big_pie';
div.appendChild(canvas);
bg.onmousedown = function (e)
{
this.style.display = 'none';
document.body.removeChild(this);
e.stopPropagation();
}
div.onmousedown = function (e)
{
e.stopPropagation();
}
var data = e.target.__object__.data;
var pie = new RGraph.Pie('big_pie', data);
pie.Set('chart.align', 'left');
pie.Set('chart.colors', ['red','#3F3','#ccc']);
pie.Set('chart.key', ['Jane', 'Fred', 'John']);
pie.Set('chart.key.shadow', true);
pie.Set('chart.key.shadow.blur', 15);
pie.Set('chart.key.shadow.offsetx', 0);
pie.Set('chart.key.shadow.offsety', 0);
pie.Set('chart.key.shadow.color', 'gray');
pie.Set('chart.key.rounded', true);
pie.Set('chart.gutter.top', 2);
pie.Set('chart.gutter.bottom', 2);
pie.Set('chart.gutter.left', 2);
pie.Set('chart.gutter.right', 2);
pie.Draw();
setTimeout(function () {bg.style.opacity = 0.2;}, 50);
setTimeout(function () {bg.style.opacity = 0.4;}, 100);
setTimeout(function () {bg.style.opacity = 0.6;}, 150);
setTimeout(function () {bg.style.opacity = 0.8;}, 200);
setTimeout(function () {bg.style.opacity = 1;}, 250);
}
</script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-54706-2']);
_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>
</head>
<body>
<!-- Social networking buttons -->
<div id="social_icons" class="warning" style="border-radius: 10px; top: 1px; position: fixed; width: 120px; height: 20px">
<!-- <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%20javascript%20charts%20library%20supporting%20a%20wide%20range%20of%20different%20chart%20types&title=RGraph:%20Javascript%20charts%20%26%20graph%20library" target="_blank"><img src="../images/delicious.png" alt="Bookmark with delicious" width="22" height="22" border="0" style="position: relative; top: 1px" /></a> -->
<a href="http://twitter.com/home/?status=RGraph%3A%20Javascript+charts+library+http%3A%2F%2Fwww.rgraph.net+%23rgraph+%23html5+%23canvas+%23javascript+%23charts+@_rgraph" target="_blank" title="Mention RGraph on Twitter"><img src="../images/twitter.png" alt="Mention RGraph on Twitter"/></a>
<iframe src="http://www.facebook.com/plugins/like.php?app_id=253862424642173&href=http%3A%2F%2Fwww.rgraph.net&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font=arial&height=21" scrolling="no" frameborder="0" style="width: 80px; height:21px; position: relative; top: 1px"></iframe>
</div>
<script>
// Opera fix
if (navigator.userAgent.indexOf('Opera') == -1) {
document.getElementById("social_icons").style.position = 'fixed';
}
</script>
<div id="google_plusone">
<!-- Place this tag where you want the +1 button to render -->
<g:plusone href="http://www.rgraph.net"></g:plusone>
</div>
<!-- Social networking buttons -->
<div id="breadcrumb">
<a href="../index.html">RGraph: HTML5 Javascript charts library</a>
>
<a href="./index.html">Documentation</a>
>
Combining charts
</div>
<h1>RGraph: <span>HTML5 Javascript charts library</span> - Combining charts</h1>
<script>
if (RGraph.isIE8()) {
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 charts, 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.</div>');
}
</script>
<ul>
<li><a href="#barandline">Combining bar and line charts</a></li>
<li><a href="#combiningline">Combining Line charts</a></li>
</ul>
<a name="barandline"></a>
<h4>Combining bar and line charts</h4>
<canvas id="myCanvas" width="600" height="250" style="float: right">[No canvas support]</canvas>
<script>
var bar = new RGraph.Bar('myCanvas', [4,5,3,4,1,2,6,5,8,4,9,4]);
bar.Set('chart.title', 'A bar/line/pie combination (tooltips)');
bar.Set('chart.ymax', 15);
bar.Set('chart.text.angle', 45);
bar.Set('chart.colors', ['#ccc', 'red', 'green']);
bar.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
bar.Set('chart.tooltips', ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']);
bar.Set('chart.background.grid.autofit', true);
bar.Set('chart.key', ['John', 'Jane', 'Fred']);
bar.Set('chart.key.shadow', true);
bar.Set('chart.key.shadow.offsetx', 0);
bar.Set('chart.key.shadow.offsety', 0);
bar.Set('chart.key.shadow.blur', 10);
bar.Set('chart.key.shadow.color', 'rgba(128,128,128,0.5)');
bar.Set('chart.key.background', 'white');
bar.Set('chart.key.rounded', true);
bar.Set('chart.background.grid.autofit', true);
bar.Set('chart.background.grid.autofit.numvlines', 12);
bar.Set('chart.background.grid.autofit.numhlines', 5);
bar.Set('chart.gutter.bottom', 30);
bar.Set('chart.gutter.right', 5);
// Define the line first so that it can be added to the bar chart
var line = new RGraph.Line('myCanvas', [1,3,4,3,2,1,4,5,2,3,8,8], [5,6,7,9,7,5,6,3,5,2,5,1]);
line.Set('chart.background.grid', false);
line.Set('chart.linewidth', 2);
line.Set('chart.colors', ['red', 'green']);
line.Set('chart.tickmarks', 'circle');
line.Set('chart.labels.ingraph', ['January',11,,'February']);
line.Set('chart.highlight.fill', 'black');
line.Set('chart.animation.unfold.x', true);
// This would all be done programmatically normally, and linked to the key, so that if you change a name in the key,
// it changes in all of the tooltips too
line.Set('chart.tooltips', [
'<b>January</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'January\')"></canvas> <div id="red"></div>Jane: 1<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 4',
'<b>February</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'February\')"></canvas> <div id="red"></div>Jane: 6<br /><div id="green"></div>Fred: 6<br /><div id="gray"></div>John: 5',
'<b>March</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'March\')"></canvas> <div id="red"></div>Jane: 4<br /><div id="green"></div>Fred: 7<br /><div id="gray"></div>John: 3',
'<b>April</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'April\')"></canvas> <div id="red"></div>Jane: 3<br /><div id="green"></div>Fred: 9<br /><div id="gray"></div>John: 4',
'<b>May</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'May\')"></canvas> <div id="red"></div>Jane: 2<br /><div id="green"></div>Fred: 7<br /><div id="gray"></div>John: 1',
'<b>June</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'June\')"></canvas> <div id="red"></div>Jane: 1<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 2',
'<b>July</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'July\')"></canvas> <div id="red"></div>Jane: 4<br /><div id="green"></div>Fred: 6<br /><div id="gray"></div>John: 6',
'<b>Aug</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'August\')"></canvas> <div id="red"></div>Jane: 5<br /><div id="green"></div>Fred: 3<br /><div id="gray"></div>John: 5',
'<b>September</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'September\')"></canvas> <div id="red"></div>Jane: 2<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 8',
'<b>October</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'October\')"></canvas> <div id="red"></div>Jane: 3<br /><div id="green"></div>Fred: 2<br /><div id="gray"></div>John: 4',
'<b>November</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'November\')"></canvas> <div id="red"></div>Jane: 8<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 9',
'<b>December</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'December\')"></canvas> <div id="red"></div>Jane: 8<br /><div id="green"></div>Fred: 1<br /><div id="gray"></div>John: 4',
'<b>January</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'January\')"></canvas> <div id="red"></div>Jane: 1<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 4',
'<b>February</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'February\')"></canvas> <div id="red"></div>Jane: 6<br /><div id="green"></div>Fred: 6<br /><div id="gray"></div>John: 5',
'<b>March</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'March\')"></canvas> <div id="red"></div>Jane: 4<br /><div id="green"></div>Fred: 7<br /><div id="gray"></div>John: 3',
'<b>April</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'April\')"></canvas> <div id="red"></div>Jane: 3<br /><div id="green"></div>Fred: 9<br /><div id="gray"></div>John: 4',
'<b>May</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'May\')"></canvas> <div id="red"></div>Jane: 2<br /><div id="green"></div>Fred: 7<br /><div id="gray"></div>John: 1',
'<b>June</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'June\')"></canvas> <div id="red"></div>Jane: 1<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 2',
'<b>July</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'July\')"></canvas> <div id="red"></div>Jane: 4<br /><div id="green"></div>Fred: 6<br /><div id="gray"></div>John: 6',
'<b>August</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'August\')"></canvas> <div id="red"></div>Jane: 5<br /><div id="green"></div>Fred: 3<br /><div id="gray"></div>John: 5',
'<b>September</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'September\')"></canvas> <div id="red"></div>Jane: 2<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 8',
'<b>October</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'October\')"></canvas> <div id="red"></div>Jane: 3<br /><div id="green"></div>Fred: 2<br /><div id="gray"></div>John: 4',
'<b>November</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'November\')"></canvas> <div id="red"></div>Jane: 8<br /><div id="green"></div>Fred: 5<br /><div id="gray"></div>John: 9',
'<b>December</b><br /> <canvas width="50" height="50" id="__tooltip_canvas__" style="float: right" onclick="enlarge_tooltip_graph(event, \'December\')"></canvas> <div id="red"></div>Jane: 8<br /><div id="green"></div>Fred: 1<br /><div id="gray"></div>John: 4'
]);
//line.Set('chart.tooltips.highlight', false);
// No need to call Draw() - the bar chart will do it
// Add a Line chart tooltip event that draws the tooltip Pie charts
RGraph.AddCustomEventListener(line, 'ontooltip', CreateTooltipGraph);
// Add the line chart to the bar chart
bar.Set('chart.line', line);
// Now use effects
//line.Draw();
//bar.Draw();
RGraph.Effects.Fade.In(bar);
RGraph.Effects.Bar.Grow(bar);
RGraph.Effects.Line.Unfold(bar.Get('chart.line'));
/**
* This is the function that creates the tooltip charts
*/
function CreateTooltipGraph (obj)
{
// If the tooltip canvas doesn't exist, don't try to create the
// tooltip pie chart
if (!document.getElementById("__tooltip_canvas__")) {
return;
}
var index = RGraph.Registry.Get('chart.tooltip').__index__;
var tooltip = obj.Get('chart.tooltips')[index];
// Extract the data for the obj.Get('chart.tooltips')[index]ie chart froim the tooltip
var jane_data = Number(tooltip.replace(/.*Jane: (\d+).*/, '$1'));
var fred_data = Number(tooltip.replace(/.*Fred: (\d+).*/, '$1'));
var john_data = Number(tooltip.replace(/.*John: (\d+).*/, '$1'));
var pie_data = [jane_data,fred_data,john_data];
// This data could be dynamic
var pie = new RGraph.Pie('__tooltip_canvas__', pie_data);
pie.Set('chart.gutter.top', 2);
pie.Set('chart.gutter.bottom', 2);
pie.Set('chart.gutter.left', 2);
pie.Set('chart.gutter.right', 2);
pie.Set('chart.colors', ['red','#3F3','#ccc']);
//pie.Draw();
RGraph.Effects.Pie.Grow(pie);
pie.canvas.style.cursor = 'pointer';
}
</script>
<p>
This is an example of combining Bar and Line charts. It's quite straight-forward, and the code here shows you how it can be achieved.
</p>
<p>
If the values for the line and bar result in different Y scales you may need to specify the <i>chart.ymax</i> property for each chart
so that the scales are the same. The line turns off Y labels so as not to overwrite the Bars labels.
</p>
<b>Tooltips</b>
<p>
You can have tooltips on the Line and Bar chart by setting <i>chart.tooltips.highlight</i> to <i>false</i>, as shown.
The order in which you create the charts is also important, you must define the Bar chart first, and subsequently the Line
chart.
</p>
<h4>Update - 28th August 2011</h4>
<p>
You can now have tooltips on both the Line chart <b>and</b> the Bar chart, as is shown in the chart here. Keep in mind
that you will need to have highlighting turned off on both chart types - <i>chart.tooltips.highlight</i>.
</p>
<pre class="code">
<script>
line.Set('chart.tooltips.highlight', false);
bar.Set('chart.tooltips.highlight', false);
</script>
</pre>
<p>
Because the tooltips are only triggered by the Line chart, you should put all of the information, for both the Line and the
Bar chart, in the tooltips.
</p>
<a name="combiningline"></a>
<h4>Combining Line charts</h4>
<!-- This is the canvas that both the line charts use -->
<canvas id="myCanvas2" width="600" height="250" style="float: right">[No canvas support]</canvas>
<script>
line2 = new RGraph.Line('myCanvas2', [51,22,23,33,35,23,32,45]);
line2.Set('chart.hmargin', 10);
line2.Set('chart.labels', ['Kiff', 'Wayne', 'Pete', 'Lou', 'Jake', 'Jo', 'Fred', 'Bob']);
line2.Set('chart.linewidth', 3);
line2.Set('chart.shadow', true);
line2.Set('chart.shadow.offsetx', 2);
line2.Set('chart.shadow.offsety', 2);
line2.Set('chart.ymax', 65);
line2.Set('chart.units.post', 'l');
line2.Set('chart.noendxtick', true);
line2.Set('chart.title', 'An example of axes both sides');
line2.Set('chart.title.yaxis', 'Cost ($)');
line2.Set('chart.title.yaxis.align', 'right');
line2.Set('chart.title.yaxis.pos', 0.8);
line2.Set('chart.gutter.left', 55);
line2.Set('chart.gutter.right', 55);
line2.Set('chart.background.grid.autofit', true);
line2.Draw();
line3 = new RGraph.Line('myCanvas2', [42,50,51,23,46,48,65,11]);
line3.Set('chart.title.yaxis', 'Volume (l)');
line3.Set('chart.hmargin', 10);
line3.Set('chart.linewidth', 3);
line3.Set('chart.shadow', true);
line3.Set('chart.shadow.offsetx', 2);
line3.Set('chart.shadow.offsety', 2);
line3.Set('chart.yaxispos', 'right');
line3.Set('chart.gutter.left', 55);
line3.Set('chart.gutter.right', 55);
line3.Set('chart.noendxtick', true);
line3.Set('chart.background.grid', false);
line3.Set('chart.ymax', 100);
line3.Set('chart.colors', ['blue', 'red']);
line3.Set('chart.units.pre', '$');
line3.Set('chart.key', ['Cost', 'Volume']);
line3.Set('chart.key.background', 'rgba(255,255,255,0.8)');
line3.Draw();
</script>
<p>
Another type of chart you may want is a line chart with Y axes on both sides, as illustrated on the right. You should
be careful with this chart type as it can easily lead to confusion.
</p>
<p>
This chart is made up from two line charts, one with the Y axis on the left and one on the right. The code that makes up
this chart is below.
</p>
<p>
The only reason to combine line charts is to get Y axes on the left and right. If you simply want mutiple lines,
you can do this without combining any charts. <a href="../examples/line.html">See the line chart example page</a>
</p>
<br clear="all" />
<pre class="code">
<script>
window.onload = function
{
line2 = new RGraph.Line('myCanvas2', [51,22,23,33,35,23,32,45]);
line2.Set('chart.hmargin', 10);
line2.Set('chart.labels', ['Kiff', 'Wayne', 'Pete', 'Lou', 'Jake', 'Jo', 'Fred', 'Bob']);
line2.Set('chart.linewidth', 3);
line2.Set('chart.shadow', true);
line2.Set('chart.shadow.offsetx', 2);
line2.Set('chart.shadow.offsety', 2);
line2.Set('chart.ymax', 65);
line2.Set('chart.units.post', 'l');
line2.Set('chart.noxaxis', true);
line2.Set('chart.noendxtick', true);
line2.Set('chart.title', 'An example of axes both sides');
line2.Draw();
line3 = new RGraph.Line('myCanvas2', [42,50,51,23,46,48,65,11]);
line3.Set('chart.hmargin', 10);
line3.Set('chart.linewidth', 3);
line3.Set('chart.shadow', true);
line3.Set('chart.shadow.offsetx', 2);
line3.Set('chart.shadow.offsety', 2);
line3.Set('chart.yaxispos', 'right');
line3.Set('chart.noendxtick', true);
line3.Set('chart.background.grid', false);
line3.Set('chart.ymax', 65);
line3.Set('chart.colors', ['blue', 'red']);
line3.Set('chart.units.pre', '$');
line3.Set('chart.key', ['Cost', 'Volume']);
line3.Set('chart.key.background', 'rgba(255,255,255,0.5)');
line3.Draw();
}
</script>
</pre>
</body>
</html>
|