In [1]:
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.
Out[1]:
true
In [2]:
Daru::View.plotting_library = :highcharts
Out[2]:
:highcharts
In [3]:
graph = Daru::View::Plot.new
Out[3]:
#<Daru::View::Plot:0x007ff4fb21eab0 @data=[], @options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007ff4fb21e948 @series_data=[{:type=>nil, :name=>nil, :data=>[]}], @options={:title=>{:text=>nil}, :legend=>{:layout=>"vertical", :style=>{}}, :xAxis=>{}, :yAxis=>{:title=>{:text=>nil}, :labels=>{}}, :tooltip=>{:enabled=>true}, :credits=>{:enabled=>false}, :plotOptions=>{:areaspline=>{}}, :chart=>{:defaultSeriesType=>"line", :renderTo=>nil}, :subtitle=>{}}, @html_options={}, @placeholder="awlyviqexoz">>
In [4]:
graph.chart.class
Out[4]:
LazyHighCharts::HighChart
In [5]:
graph.chart.to_html
Out[5]:
"                <script type=\"text/javascript\">\n        (function() {\n\n          var onload = window.onload;\n          window.onload = function(){\n            if (typeof onload == \"function\") onload();\n                    var options = { \"title\": { \"text\": null },\"legend\": { \"layout\": \"vertical\",\"style\": {  } },\"xAxis\": {  },\"yAxis\": { \"title\": { \"text\": null },\"labels\": {  } },\"tooltip\": { \"enabled\": true },\"credits\": { \"enabled\": false },\"plotOptions\": { \"areaspline\": {  } },\"chart\": { \"defaultSeriesType\": \"line\",\"renderTo\": \"ybotevlzauq\" },\"subtitle\": {  },\"series\": [{ \"type\": null,\"name\": null,\"data\": [  ] }] };\n        \n        window.chart_ybotevlzauq = new Highcharts.Chart(options);\n\n          };\n                })()\n        </script>\n\n<div id=\"ybotevlzauq\"></div>"
In [6]:
graph.show_in_iruby
Out[6]:
In [7]:
g = Daru::View::Plot.new      
graph = g.chart.tap do |f|
        f.series(:name => 'John', :data => [3, 20])
        f.series(:name => 'Jane', :data => [1, 3])
        # without overriding
        f.options[:chart][:defaultSeriesType] = "area"
        f.options[:chart][:inverted] = true
        f.options[:legend][:layout] = "horizontal"
        f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
      end
Out[7]:
In [8]:
graph.series_data
Out[8]:
[{:type=>nil, :name=>nil, :data=>[]}, {:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
In [9]:
g.show_in_iruby
Out[9]:
In [10]:
graph.series_data.delete({type: nil, :name => nil, :data => []})
Out[10]:
{:type=>nil, :name=>nil, :data=>[]}
In [11]:
graph.series_data
Out[11]:
[{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
In [12]:
graph.options[:xAxis][:categories]
Out[12]:
["uno", "dos", "tres", "cuatro"]
In [13]:
graph.options[:legend][:layout]
Out[13]:
"horizontal"
In [14]:
df =     Daru::DataFrame.new(
      {
        a: [1, 3, 5, 2, 5, 0],
        b: [1, 5, 2, 5, 1, 0],
        c: [1, 6, 7, 2, 6, 0]
      }, index: 'a'..'f'
    )
Out[14]:
Daru::DataFrame(6x3)
a b c
a 1 1 1
b 3 5 6
c 5 2 7
d 2 5 2
e 5 1 6
f 0 0 0
In [19]:
df.class
Out[19]:
Daru::DataFrame
In [20]:
Daru::View::Plot.new(df, type: :bar)
Out[20]:
#<Daru::View::Plot:0x007ff4fbb52258 @data=#<Daru::DataFrame(6x3)>
       a   b   c
   a   1   1   1
   b   2   5   6
   c   3   2   7
   d   4   5   2
   e   5   1   6
   f   6   0   0, @options={:type=>:bar}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007ff4fbb5aea8 @series_data=[{:type=>:bar, :name=>nil, :data=>[[1, 1, 1], [2, 5, 6], [3, 2, 7], [4, 5, 2], [5, 1, 6], [6, 0, 0]]}], @options={:type=>:bar}, @html_options={}, @placeholder="dqapcfsieuj">>
In [21]:
df =     Daru::DataFrame.new(
      {
        a: [1, 2, 3, 4, 5, 6],
        b: [1, 5, 2, 5, 1, 0],
        c: [1, 6, 7, 2, 6, 0]
      }, index: 'a'..'f'
    )
Out[21]:
Daru::DataFrame(6x3)
a b c
a 1 1 1
b 2 5 6
c 3 2 7
d 4 5 2
e 5 1 6
f 6 0 0
In [22]:
plt = Daru::View::Plot.new(df, type: :line, x: :a, y: :c)
Out[22]:
#<Daru::View::Plot:0x007ff4fb613328 @data=#<Daru::DataFrame(6x3)>
       a   b   c
   a   1   1   1
   b   2   5   6
   c   3   2   7
   d   4   5   2
   e   5   1   6
   f   6   0   0, @options={:type=>:line, :x=>:a, :y=>:c}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007ff4fb61bf78 @series_data=[{:type=>:line, :name=>nil, :data=>[[1, 1, 1], [2, 5, 6], [3, 2, 7], [4, 5, 2], [5, 1, 6], [6, 0, 0]]}], @options={:type=>:line, :x=>:a, :y=>:c}, @html_options={}, @placeholder="yxwnautzqfo">>
In [23]:
plt.show_in_iruby
Out[23]:
In [24]:
plt.div
Out[24]:
"                <script type=\"text/javascript\">\n        (function() {\n\n          var onload = window.onload;\n          window.onload = function(){\n            if (typeof onload == \"function\") onload();\n                    var options = { \"type\": \"line\",\"x\": \"a\",\"y\": \"c\",\"chart\": { \"renderTo\": \"tvyzbqcamsh\" },\"series\": [{ \"type\": \"line\",\"name\": null,\"data\": [ [ 1,1,1 ],[ 2,5,6 ],[ 3,2,7 ],[ 4,5,2 ],[ 5,1,6 ],[ 6,0,0 ] ] }] };\n        \n        window.chart_tvyzbqcamsh = new Highcharts.Chart(options);\n\n          };\n                })()\n        </script>\n\n<div id=\"tvyzbqcamsh\"></div>"
In [25]:
df.delete_vector :b
Out[25]:
Daru::DataFrame(6x2)
a c
a 1 1
b 2 6
c 3 7
d 4 2
e 5 6
f 6 0
In [26]:
plt = Daru::View::Plot.new(df, type: :line)
Out[26]:
#<Daru::View::Plot:0x007ff4fb642d80 @data=#<Daru::DataFrame(6x2)>
       a   c
   a   1   1
   b   2   6
   c   3   7
   d   4   2
   e   5   6
   f   6   0, @options={:type=>:line}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007ff4fb640a08 @series_data=[{:type=>:line, :name=>nil, :data=>[[1, 1], [2, 6], [3, 7], [4, 2], [5, 6], [6, 0]]}], @options={:type=>:line}, @html_options={}, @placeholder="pjinalcgfrv">>
In [27]:
plt.show_in_iruby
Out[27]: