In [1]:
require 'daru/view'
Out[1]:
true
In [2]:
require 'daru'
Out[2]:
true
In [3]:
Daru::View.load_lib_in_iruby('Nyaplot')
In [4]:
Daru::View.plotting_library = :highcharts
Out[4]:
:highcharts
In [5]:
df = Daru::DataFrame.new({a:['A', 'B', 'C', 'D', 'E'], b:[10,20,30,40,50]})
Out[5]:
Daru::DataFrame(5x2)
a b
0 A 10
1 B 20
2 C 30
3 D 40
4 E 50
In [6]:
plt = Daru::View::Plot.new df, type: :bar, x: :a, y: :b
Out[6]:
#<Daru::View::Plot:0x007fc19a21b728 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fc199198838 @series_data=[{:type=>:bar, :name=>nil, :data=>[["A", 10], ["B", 20], ["C", 30], ["D", 40], ["E", 50]]}], @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="graph">>
In [7]:
plt.class
Out[7]:
Daru::View::Plot
In [8]:
plt.div
Out[8]:
"                <script type=\"text/javascript\">\n        $(function() {\n\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\": \"cebvwfdmznl\" },\"subtitle\": {  },\"series\": [{ \"type\": \"bar\",\"name\": null,\"data\": [ [ \"A\",10 ],[ \"B\",20 ],[ \"C\",30 ],[ \"D\",40 ],[ \"E\",50 ] ] }] };\n        \n        window.chart_cebvwfdmznl = new Highcharts.Chart(options);\n\n                });\n        </script>\n\n<div id=\"cebvwfdmznl\"></div>"
In [9]:
plt.init_iruby
In [10]:
plt.show_in_iruby
Out[10]:
In [11]:
plt_gauge = Daru::View::Plot.new df, type: :gauge, x: :a, y: :b
Out[11]:
#<Daru::View::Plot:0x007fc19aad07b0 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fc19a1716d8 @series_data=[{:type=>:gauge, :name=>nil, :data=>[["A", 10], ["B", 20], ["C", 30], ["D", 40], ["E", 50]]}], @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="graph">>
In [12]:
plt_gauge.show_in_iruby
Out[12]:
In [13]:
dv = Daru::Vector.new [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
Out[13]:
Daru::Vector(8)
0 43934
1 52503
2 57177
3 69658
4 97031
5 119931
6 137133
7 154175
In [14]:
plt_line = Daru::View::Plot.new dv, type: :line
Out[14]:
#<Daru::View::Plot:0x007fc19ab09830 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fc19ab09628 @series_data=[{:type=>:line, :name=>nil, :data=>[43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]}], @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="graph">>
In [15]:
Daru::View.plotting_library
Out[15]:
:highcharts
In [16]:
plt_line = Daru::View::Plot.new dv, type: :spline
Out[16]:
#<Daru::View::Plot:0x007fc199328c20 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fc1993286d0 @series_data=[{:type=>:spline, :name=>nil, :data=>[43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]}], @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="graph">>
In [17]:
plt_line.chart
Out[17]:
#<LazyHighCharts::HighChart:0x007fc1993286d0 @series_data=[{:type=>:spline, :name=>nil, :data=>[43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]}], @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="graph">
In [18]:
plt_line.show_in_iruby
Out[18]:
In [ ]:

In [ ]: