require 'daru/view'
Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions. Install the mechanize gem version ~>2.7.5 for using mechanize functions.
true
Daru::View.plotting_library = :highcharts
:highcharts
df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5],
c: [11,22,33,44,55]},
order: [:a, :b, :c],
index: [:one, :two, :three, :four, :five])
a | b | c | |
---|---|---|---|
one | 1 | 11 | 11 |
two | 2 | 12 | 22 |
three | 3 | 13 | 33 |
four | 4 | 14 | 44 |
five | 5 | 15 | 55 |
html_code = "<table id='table_id1'>" + df.to_html_thead + df.to_html_tbody + "</table>"
"<table id='table_id1'><thead>\n \n <tr>\n <th></th>\n \n <th>a</th>\n \n <th>b</th>\n \n <th>c</th>\n \n </tr>\n \n</thead><tbody>\n \n <tr>\n <td>one</td>\n \n <td>1</td>\n \n <td>11</td>\n \n <td>11</td>\n \n </tr>\n \n <tr>\n <td>two</td>\n \n <td>2</td>\n \n <td>12</td>\n \n <td>22</td>\n \n </tr>\n \n <tr>\n <td>three</td>\n \n <td>3</td>\n \n <td>13</td>\n \n <td>33</td>\n \n </tr>\n \n <tr>\n <td>four</td>\n \n <td>4</td>\n \n <td>14</td>\n \n <td>44</td>\n \n </tr>\n \n <tr>\n <td>five</td>\n \n <td>5</td>\n \n <td>15</td>\n \n <td>55</td>\n \n </tr>\n \n\n \n</tbody></table>"
IRuby.html html_code
a | b | c | |
---|---|---|---|
one | 1 | 11 | 11 |
two | 2 | 12 | 22 |
three | 3 | 13 | 33 |
four | 4 | 14 | 44 |
five | 5 | 15 | 55 |
opts = {
data: {
table: 'table_id1'
},
chart: {
type: 'column'
},
title: {
text: 'Data extracted from a HTML table in the page'
},
yAxis: {
allowDecimals: false,
title: {
text: 'Units'
}
},
tooltip: {
formatter: "function () {
return '<b>' + this.series.name + '</b><br/>' +
this.point.y + ' ' + this.point.name.toLowerCase();
}".js_code
},
adapter: :highcharts
}
line_1 = Daru::View::Plot.new
line_1.chart.options = opts
out = html_code + line_1.div
# must show chart as well. In IRuby notebook it is not working. Works well in web application
IRuby.html out
a | b | c | |
---|---|---|---|
one | 1 | 11 | 11 |
two | 2 | 12 | 22 |
three | 3 | 13 | 33 |
four | 4 | 14 | 44 |
five | 5 | 15 | 55 |