-
Notifications
You must be signed in to change notification settings - Fork 3
/
chart.rb
72 lines (60 loc) · 1.9 KB
/
chart.rb
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
# var data = {
# labels : ["January","February","March","April","May","June","July"],
# datasets : [
# {
# fillColor : "rgba(220,220,220,0.5)",
# strokeColor : "rgba(220,220,220,1)",
# pointColor : "rgba(220,220,220,1)",
# pointStrokeColor : "#fff",
# data : [65,59,90,81,56,55,40]
# },
# {
# fillColor : "rgba(151,187,205,0.5)",
# strokeColor : "rgba(151,187,205,1)",
# pointColor : "rgba(151,187,205,1)",
# pointStrokeColor : "#fff",
# data : [28,48,40,19,96,27,100]
# }
# ]
# }
require 'tempfile'
file = Tempfile.new(['foo', ".html"], "temp" )
path = file.path
file.unlink
puts "File: #{path}"
doc = <<HTML
<html>
<body>
<canvas id="myChart" width="800" height="400"></canvas>
<script src="/Chart.js"></script>
<script type="text/javascript">
var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [65,59,90,81,56,55,40]
},
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28,48,40,19,96,27,100]
}
]
}
//Get the context of the canvas element we want to select
var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx).Line(data); //,options);
</script>
</body>
</html>
HTML
File.open path, "w+" do |f|
f.write doc
end
`open http://1234000000486.dev/#{path}`