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
graph = Daru::View::Plot.new
#<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">>
graph.chart.class
LazyHighCharts::HighChart
graph.chart.to_html
" <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>"
graph.show_in_iruby
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
graph.series_data
[{:type=>nil, :name=>nil, :data=>[]}, {:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
g.show_in_iruby
graph.series_data.delete({type: nil, :name => nil, :data => []})
{:type=>nil, :name=>nil, :data=>[]}
graph.series_data
[{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
graph.options[:xAxis][:categories]
["uno", "dos", "tres", "cuatro"]
graph.options[:legend][:layout]
"horizontal"
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'
)
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 |
df.class
Daru::DataFrame
Daru::View::Plot.new(df, type: :bar)
#<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">>
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'
)
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 |
plt = Daru::View::Plot.new(df, type: :line, x: :a, y: :c)
#<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">>
plt.show_in_iruby
plt.div
" <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>"
df.delete_vector :b
Daru::DataFrame(6x2) | ||
---|---|---|
a | c | |
a | 1 | 1 |
b | 2 | 6 |
c | 3 | 7 |
d | 4 | 2 |
e | 5 | 6 |
f | 6 | 0 |
plt = Daru::View::Plot.new(df, type: :line)
#<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">>
plt.show_in_iruby