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]:
dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category
Out[2]:
Daru::Vector(6):category
0 a
1 a
2 a
3 b
4 b
5 c
In [3]:
bar_graph1 = Daru::View::Plot.new(dv, type: :bar)
Out[3]:
#<Daru::View::Plot:0x007fec6723b738 @data=#<Daru::Vector(6):cataegory>
   0   a
   1   a
   2   a
   3   b
   4   b
   5   c, @options={:type=>:bar, :method=>:count}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007fec6723b5f8 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007fec67239a50 @properties={:type=>:bar, :options=>{:x=>"data0", :y=>"data1"}, :data=>"5f227022-dd7d-42e0-8645-1b60c76507a0"}, @xrange=[:a, :b, :c], @yrange=[0, 3]>], :options=>{}}>>
In [4]:
bar_graph1.init_script
Out[4]:
"<!-- TODO : remove the link and use downloaded js -->\n<script src=\"http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js\"></script>\n<script>if(window['d3'] === undefined ||\n   window['Nyaplot'] === undefined){\n    var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n\n\n\n    var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n\n    require.config({paths: path, shim:shim});\n\n\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n\n\tvar script = d3.select(\"head\")\n\t    .append(\"script\")\n\t    .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n\t    .attr(\"async\", true);\n\n\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n\n\n\t    var event = document.createEvent(\"HTMLEvents\");\n\t    event.initEvent(\"load_nyaplot\",false,false);\n\t    window.dispatchEvent(event);\n\t    console.log('Finished loading Nyaplotjs');\n\n\t};\n\n\n});});\n}\n</script>\n"
In [5]:
Daru::View.plotting_library
Out[5]:
:nyaplot
In [6]:
bar_graph1.div
Out[6]:
"<div id='vis-62a99d20-bf77-4dfd-ab69-4ecfd51789d3'></div>\n<script>\n(function(){\n    var render = function(){\n        var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"5f227022-dd7d-42e0-8645-1b60c76507a0\"}],\"options\":{\"width\":700,\"xrange\":[\"a\",\"b\",\"c\"],\"yrange\":[0,3]}}],\"data\":{\"5f227022-dd7d-42e0-8645-1b60c76507a0\":[{\"data0\":\"a\",\"data1\":3},{\"data0\":\"b\",\"data1\":2},{\"data0\":\"c\",\"data1\":1}]},\"extension\":[]}\n        var id_name = '#vis-62a99d20-bf77-4dfd-ab69-4ecfd51789d3';\n        Nyaplot.core.parse(model, id_name);\n\n        require(['downloadable'], function(downloadable){\n          var svg = d3.select(id_name).select(\"svg\");\n\t  if(!svg.empty())\n\t    svg.call(downloadable().filename('fig'));\n\t});\n    };\n    if(window['Nyaplot']==undefined){\n        window.addEventListener('load_nyaplot', render, false);\n\treturn;\n    } else {\n       render();\n    }\n})();\n</script>\n"
In [7]:
IRuby.html bar_graph1.div
Out[7]: