require 'daru/view'
true
Daru::View.plotting_library = :highcharts
:highcharts
graph = Daru::View::Plot.new
#<Daru::View::Plot:0x0000558908c0ba20 @data=[], @options={}, @user_options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x0000558908c0b840 @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="shmftuboncp", @user_options={}>>
graph.chart.class
LazyHighCharts::HighChart
graph.chart.to_html
"\n<script type='text/javascript'>\n\nvar event = document.createEvent(\"HTMLEvents\");\nevent.initEvent(\"load_highcharts\", false, false);\nwindow.dispatchEvent(event);\nconsole.log(\"Finish loading highchartsjs\");\n\n</script> <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\": \"wxsackeyqoz\" },\"subtitle\": { },\"series\": [{ \"type\": null,\"name\": null,\"data\": [ ] }] };\n \n window.chart_wxsackeyqoz = new Highcharts.Chart(options);\n\n };\n })()\n </script>\n\n<div id=\"wxsackeyqoz\"></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'
)
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:0x00005589084827e0 @data=#<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, @options={:type=>:bar}, @user_options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x0000558908482790 @series_data=[{:type=>:bar, :name=>nil, :data=>[[1, 1, 1], [3, 5, 6], [5, 2, 7], [2, 5, 2], [5, 1, 6], [0, 0, 0]]}], @options={:type=>:bar}, @html_options={}, @placeholder="xchswibnjda", @user_options={}>>
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'
)
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:0x0000558909905910 @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}, @user_options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x00005589099058c0 @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="iqgnyadjzpm", @user_options={}>>
plt.show_in_iruby
plt.div
"\n<script type='text/javascript'>\n\nvar event = document.createEvent(\"HTMLEvents\");\nevent.initEvent(\"load_highcharts\", false, false);\nwindow.dispatchEvent(event);\nconsole.log(\"Finish loading highchartsjs\");\n\n</script> <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\": \"cgjodaeikbq\" },\"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_cgjodaeikbq = new Highcharts.Chart(options);\n\n };\n })()\n </script>\n\n<div id=\"cgjodaeikbq\"></div>"
df.delete_vector :b
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:0x00005589096f52d8 @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}, @user_options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x00005589096f5288 @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="tdipknwjmah", @user_options={}>>
plt.show_in_iruby