In [1]:
require 'daru/view'
require 'daru'
Out[1]:
true
In [2]:
Daru::View.plotting_library = :highcharts
Out[2]:
:highcharts
In [3]:
data = [
    ['Firefox',   45.0],
    ['IE',       26.8],
    {
       :name=> 'Chrome',
       :y=> 12.8,
       :sliced=> true,
       :selected=> true
    },
    ['Safari',    8.5],
    ['Opera',     6.2],
    ['Others',   0.7]
]
plt_pie = Daru::View::Plot.new data, type: :pie
Out[3]:
#<Daru::View::Plot:0x007fa0151d2880 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fa016cd4e80 @series_data=[{:type=>:pie, :name=>nil, :data=>[["Firefox", 45.0], ["IE", 26.8], {:name=>"Chrome", :y=>12.8, :sliced=>true, :selected=>true}, ["Safari", 8.5], ["Opera", 6.2], ["Others", 0.7]]}], @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 [4]:
# this is done automatically when `Daru::View.plotting_library = :highcharts` is done.
# Daru::View.load_lib_in_iruby 'Highcharts'
In [6]:
plt_pie.show_in_iruby
Out[6]:
In [7]:
plt_pie.div
Out[7]:
"                <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\": \"zyfqsehujbw\" },\"subtitle\": {  },\"series\": [{ \"type\": \"pie\",\"name\": null,\"data\": [ [ \"Firefox\",45.0 ],[ \"IE\",26.8 ],{ \"name\": \"Chrome\",\"y\": 12.8,\"sliced\": true,\"selected\": true },[ \"Safari\",8.5 ],[ \"Opera\",6.2 ],[ \"Others\",0.7 ] ] }] };\n        \n        window.chart_zyfqsehujbw = new Highcharts.Chart(options);\n\n                });\n        </script>\n\n<div id=\"zyfqsehujbw\"></div>"
In [8]:
chart_options = {:defaultSeriesType=>"pie" , :margin=> [50, 200, 60, 170], options3d: {
            enabled: true,
            alpha: 15,
            beta: 15,
            depth: 50,
            viewDistance: 25}}
series =  [
            ['Firefox',   45.0],
            ['IE',       26.8],
            {
               :name=> 'Chrome',
               :y=> 12.8,
               :sliced=> true,
               :selected=> true
            },
            ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',   0.7]
         ]
plot_options = {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            depth: 40,
            dataLabels: {
                enabled: true,
                format: '{point.name}'
            }
        }
}
plt_pie_3d = Daru::View::Plot.new series, type: :pie, name: 'Browser share', chart: chart_options, plotOptions: plot_options
Out[8]:
#<Daru::View::Plot:0x007fa0161e6438 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fa0161e5b78 @series_data=[{:type=>:pie, :name=>"Browser share", :data=>[["Firefox", 45.0], ["IE", 26.8], {:name=>"Chrome", :y=>12.8, :sliced=>true, :selected=>true}, ["Safari", 8.5], ["Opera", 6.2], ["Others", 0.7]]}], @options={:title=>{:text=>nil}, :legend=>{:layout=>"vertical", :style=>{}}, :xAxis=>{}, :yAxis=>{:title=>{:text=>nil}, :labels=>{}}, :tooltip=>{:enabled=>true}, :credits=>{:enabled=>false}, :plotOptions=>{:pie=>{:allowPointSelect=>true, :cursor=>"pointer", :depth=>40, :dataLabels=>{:enabled=>true, :format=>"{point.name}"}}}, :chart=>{:defaultSeriesType=>"pie", :margin=>[50, 200, 60, 170], :options3d=>{:enabled=>true, :alpha=>15, :beta=>15, :depth=>50, :viewDistance=>25}}, :subtitle=>{}}, @html_options={}, @placeholder="graph">>
In [9]:
plt_pie_3d.show_in_iruby
Out[9]: