-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartjstest.html
86 lines (71 loc) · 2.84 KB
/
chartjstest.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
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script src="http://it4se.com:8080/nnnick/Chart.js/master/Chart.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header">
<h1>Page 1</h1>
</div>
<div data-role="main" class="ui-content">
<p>This is page one.</p>
<div id="graph" style="width: 100%; clear: both; display: inline-block;"></div>
<a href="#page2" data-role="button">Page two</a>
</div>
</div>
<div data-role="page" id="page2">
<div data-role="header">
<h1>Page 2</h1>
</div>
<div data-role="main" class="ui-content">
<p>This is page two</p> <a href="#page1" data-role="button">Page one</a>
</div>
</div>
<script>
function makeChart (elem, labels, values, title,w,h) {
var data = {
labels: labels,
datasets : values
};
var container = $('<div style="float:left;"><h4 style="margin:0">' + title + '</h4></div>').css({'padding': '10px', 'border':'1px solid #ccc'});
var ctx = $('<canvas/>', {'Width':w?w:200,'Height':h?h:200});
$(container).append(ctx);
$(elem).append(container);
var opts = {
multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>",
legendTemplate : '<ol style="font-size: 0.8em; list-style-type: none;">'
+'<% for (var i=0; i<datasets.length; i++) { %>'
+'<li>'
+'<span style=\"border: 1px solid #ccc; padding-left: 16px; margin-right: 6px; background-color:<%=datasets[i].fillColor%>\"> </span> '
+'<% if (datasets[i].label) { %><%= datasets[i].label %><% } %>'
+'</li>'
+'<% } %>'
+'</ol>'
};
var myBarChart = new Chart(ctx[0].getContext("2d")).Bar(data, opts);
var legend = myBarChart.generateLegend();
$(container).append(legend);
}
var vals = [
{
label: "Arm 1",
fillColor: "rgba(220,220,220,0.5)",
data: [65, 59, 88]
},
{
label: "Arm 2",
fillColor: "rgba(151,187,205,0.5)",
data: [28, 48, 99]
}
];
makeChart ('#graph', ["Pretest", "Posttest", "Repeat"], vals, 'Test chart', 200);
makeChart ('#graph', ["Pretest", "Posttest", "Repeat"], vals, 'Test chart', 200);
</script>
</body>
</html>