{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.\n", "\n", "Install the mechanize gem version ~>2.7.5 for using mechanize functions.\n" ] }, { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru/view'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", " /* BEGIN google_visualr.js */\n", "\n", "if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) {\n", "window['google'] = {};\n", "}\n", "if (!window['google']['loader']) {\n", "window['google']['loader'] = {};\n", "google.loader.ServiceBase = 'https://www.google.com/uds';\n", "google.loader.GoogleApisBase = 'https://ajax.googleapis.com/ajax';\n", "google.loader.ApiKey = 'notsupplied';\n", "google.loader.KeyVerified = true;\n", "google.loader.LoadFailure = false;\n", "google.loader.Secure = true;\n", "google.loader.GoogleLocale = 'www.google.com';\n", "google.loader.ClientLocation = null;\n", "google.loader.AdditionalParams = '';\n", "(function() {function g(a){return a in l?l[a]:l[a]=-1!=navigator.userAgent.toLowerCase().indexOf(a)}var l={};function m(a,b){var c=function(){};c.prototype=b.prototype;a.ca=b.prototype;a.prototype=new c}function n(a,b,c){var d=Array.prototype.slice.call(arguments,2)||[];return function(){return a.apply(b,d.concat(Array.prototype.slice.call(arguments)))}}function p(a){a=Error(a);a.toString=function(){return this.message};return a}\n", "function q(a,b){a=a.split(/\\./);for(var c=window,d=0;d\\x3c/script>\"):(g(\"safari\")||g(\"konqueror\"))&&window.setTimeout(B,10)),x.push(a)):y(window,\"load\",a)};t(\"google.setOnLoadCallback\",google.ba);\n", "function y(a,b,c){if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent(\"on\"+b,c);else{var d=a[\"on\"+b];a[\"on\"+b]=null!=d?C([c,d]):c}}function C(a){return function(){for(var b=0;b\\x3c/script>'):\"css\"==a&&document.write('')};\n", "t(\"google.loader.writeLoadTag\",google.loader.f);google.loader.Z=function(a){w=a};t(\"google.loader.rfm\",google.loader.Z);google.loader.aa=function(a){for(var b in a)\"string\"==typeof b&&b&&\":\"==b.charAt(0)&&!v[b]&&(v[b]=new E(b.substring(1),a[b]))};t(\"google.loader.rpl\",google.loader.aa);google.loader.$=function(a){if((a=a.specs)&&a.length)for(var b=0;b\\x3c/script>')},K.Mi=function(b){var c=K.global.document,d=c.createElement(\"script\");d.type=C;d.src=b;d.defer=!1;d.async=!1;c.head.appendChild(d)},\n", "K.Wl=function(b,c){if(K.tg()){var d=K.global.document;if(!K.Ge&&d.readyState==t){if(/\\bdeps.js$/.test(b))return!1;throw Error('Cannot write \"'+b+'\" after document load');}void 0===c?K.fi?(K.eh=!0,c=\" onreadystatechange='goog.onScriptLoad_(this, \"+ ++K.Sg+\")' \",d.write(n+b+'\"'+c+\">\\x3c/script>\")):K.Ge?K.Mi(b):K.Vl(b):d.write('\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line1.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(70x2) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "
01
000
1110
2223
3317
4418
559
6611
7727
8833
9940
101032
111135
121230
131340
141442
151547
161644
171748
181852
191954
202042
212155
222256
232357
242460
252550
262652
272751
282849
292953
.........
696980
" ], "text/plain": [ "#\n", " 0 1\n", " 0 0 0\n", " 1 1 10\n", " 2 2 23\n", " 3 3 17\n", " 4 4 18\n", " 5 5 9\n", " 6 6 11\n", " 7 7 27\n", " 8 8 33\n", " 9 9 40\n", " 10 10 32\n", " 11 11 35\n", " 12 12 30\n", " 13 13 40\n", " 14 14 42\n", " ... ... ..." ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "time_popularity = [\n", " [0, 0], [1, 10], [2, 23], [3, 17], [4, 18], [5, 9],\n", " [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35],\n", " [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],\n", " [18, 52], [19, 54], [20, 42], [21, 55], [22, 56], [23, 57],\n", " [24, 60], [25, 50], [26, 52], [27, 51], [28, 49], [29, 53],\n", " [30, 55], [31, 60], [32, 61], [33, 59], [34, 62], [35, 65],\n", " [36, 62], [37, 58], [38, 55], [39, 61], [40, 64], [41, 65],\n", " [42, 63], [43, 66], [44, 67], [45, 69], [46, 69], [47, 70],\n", " [48, 72], [49, 68], [50, 66], [51, 65], [52, 67], [53, 70],\n", " [54, 71], [55, 72], [56, 73], [57, 75], [58, 70], [59, 68],\n", " [60, 64], [61, 60], [62, 65], [63, 67], [64, 68], [65, 69],\n", " [66, 70], [67, 72], [68, 75], [69, 80]\n", " ]\n", "df_tp = Daru::DataFrame.rows(time_popularity)\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#\n", " 0 1\n", " 0 0 0\n", " 1 1 10\n", " 2 2 23\n", " 3 3 17\n", " 4 4 18\n", " 5 5 9\n", " 6 6 11\n", " 7 7 27\n", " 8 8 33\n", " 9 9 40\n", " 10 10 32\n", " 11 11 35\n", " 12 12 30\n", " 13 13 40\n", " 14 14 42\n", " ... ... ..., @options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @chart=#\"number\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={}>>" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dv = Daru::View::Plot.new(df_tp)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={}>" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "line_dv.chart" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dv.chart.data_table" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{:pageSize=>10}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dv.chart.data_table.options = {pageSize: 10}" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"number\", :label=>\"0\"}, {:type=>\"number\", :label=>\"1\"}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #], [#, #]], @options={:pageSize=>10}>" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dv.chart.data_table" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{}\n" ] }, { "data": { "text/plain": [ "{\"hAxis\"=>{:title=>\"Time\"}, \"vAxis\"=>{:title=>\"Popularity\"}}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p line_dv.chart.options\n", "line_dv.chart.options = {\n", " hAxis: {\n", " title: 'Time'\n", " },\n", " vAxis: {\n", " title: 'Popularity'\n", " }\n", " }" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dv.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# dataframe `df_tp` column name is default (df_tp.vectors is 0, 1) . Let's update it.\n", "line_dv.chart.data_table.cols[0] = {type: 'number',label: 'X'}\n", "line_dv.chart.data_table.cols[1] = {type: 'number', label: 'Dogs'}\n", "line_dv.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(5x2) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
citypopulation
0New York City, NY8175000
1Los Angeles, CA3792000
2Chicago, IL2695000
3Houston, TX2099000
4Philadelphia, PA1526000
" ], "text/plain": [ "#\n", " city population\n", " 0 New York C 8175000\n", " 1 Los Angele 3792000\n", " 2 Chicago, I 2695000\n", " 3 Houston, T 2099000\n", " 4 Philadelph 1526000" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "city = Daru::Vector.new(['New York City, NY','Los Angeles, CA','Chicago, IL', 'Houston, TX', 'Philadelphia, PA'], name: 'city')\n", "population = Daru::Vector.new([ 8175000, 3792000,2695000,2099000, 1526000], name: '2010 Population')\n", "df_population_us_city = Daru::DataFrame.new(city: city, population: population)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#\n", " city population\n", " 0 New York C 8175000\n", " 1 Los Angele 3792000\n", " 2 Chicago, I 2695000\n", " 3 Houston, T 2099000\n", " 4 Philadelph 1526000, @options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @chart=#\"string\", :label=>:city}, {:type=>\"number\", :label=>:population}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={}>>" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_basic = Daru::View::Plot.new(df_population_us_city)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>:city}, {:type=>\"number\", :label=>:population}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={}>" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_basic.chart" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#\n", " city population\n", " 0 New York C 8175000\n", " 1 Los Angele 3792000\n", " 2 Chicago, I 2695000\n", " 3 Houston, T 2099000\n", " 4 Philadelph 1526000, @options={}, @adapter=Daru::View::Adapter::GooglechartsAdapter, @chart=#\"string\", :label=>:city}, {:type=>\"number\", :label=>:population}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={}>>" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic = Daru::View::Plot.new(df_population_us_city, type: :bar)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{:title=>\"Population of Largest U.S. Cities\", :chartArea=>{:width=>\"50%\"}, :hAxis=>{:title=>\"Total Population\", :minValue=>0}, :vAxis=>{:title=>\"City\"}}" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "options = {\n", " title: 'Population of Largest U.S. Cities',\n", " chartArea: {width: '50%'},\n", " hAxis: {\n", " title: 'Total Population',\n", " minValue: 0\n", " },\n", " vAxis: {\n", " title: 'City'\n", " }\n", " };" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{\"title\"=>\"Population of Largest U.S. Cities\", \"chartArea\"=>{:width=>\"50%\"}, \"hAxis\"=>{:title=>\"Total Population\", :minValue=>0}, \"vAxis\"=>{:title=>\"City\"}}" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.chart.options= options" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "#\"string\", :label=>:city}, {:type=>\"number\", :label=>:population}], @rows=[[#, #], [#, #], [#, #], [#, #], [#, #]], @options={}>, @listeners=[], @version=\"1.0\", @language=nil, @material=false, @options={\"title\"=>\"Population of Largest U.S. Cities\", \"chartArea\"=>{:width=>\"50%\"}, \"hAxis\"=>{:title=>\"Total Population\", :minValue=>0}, \"vAxis\"=>{:title=>\"City\"}}>" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.chart" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.chart.options[:pageSize] = 3" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.show_in_iruby # or bar_basic.chart" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{\"title\"=>\"Population of Largest U.S. Cities\", \"chartArea\"=>{:width=>\"50%\"}, \"hAxis\"=>{:title=>\"Total Population\", :minValue=>0}, \"vAxis\"=>{:title=>\"City\"}, :pageSize=>3}" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic.chart.options" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(22x2) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
langspeakers
0Assamese13
1Bengali83
2Bodo1.4
3Dogri2.3
4Gujarati46
5Hindi300
6Kannada38
7Kashmiri5.5
8Konkani5
9Maithili20
10Malayalam33
11Manipuri1.5
12Marathi72
13Nepali2.9
14Oriya33
15Punjabi29
16Sanskrit0.01
17Santhali6.5
18Sindhi2.5
19Tamil61
20Telugu74
21Urdu52
" ], "text/plain": [ "#\n", " lang speakers\n", " 0 Assamese 13\n", " 1 Bengali 83\n", " 2 Bodo 1.4\n", " 3 Dogri 2.3\n", " 4 Gujarati 46\n", " 5 Hindi 300\n", " 6 Kannada 38\n", " 7 Kashmiri 5.5\n", " 8 Konkani 5\n", " 9 Maithili 20\n", " 10 Malayalam 33\n", " 11 Manipuri 1.5\n", " 12 Marathi 72\n", " 13 Nepali 2.9\n", " 14 Oriya 33\n", " ... ... ..." ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lang = Daru::Vector.new(['Assamese', 'Bengali','Bodo','Dogri', 'Gujarati', 'Hindi','Kannada', 'Kashmiri', 'Konkani','Maithili', 'Malayalam', 'Manipuri','Marathi', 'Nepali', 'Oriya','Punjabi', 'Sanskrit', 'Santhali', 'Sindhi', 'Tamil', 'Telugu','Urdu'] , name: 'Language')\n", "speakers = Daru::Vector.new([13, 83, 1.4, 2.3, 46, 300, 38, 5.5, 5, 20, 33, 1.5, 72, 2.9,33,29, 0.01, 6.5,2.5, 61, 74, 52] , name: 'Speakers (in millions)')\n", "df_lang = Daru::DataFrame.new(lang: lang, speakers: speakers)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t_lang = Daru::View::Table.new(df_lang, {pageSize: 5})\n", "t_lang.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pie_lang = Daru::View::Plot.new(t_lang.table, {type: :pie, title: 'Indian Language Use', width: 800, height: 700})\n", "pie_lang.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# add/update new options\n", "# there are a lot of options and configuration we can do in google pie charts\n", "# refere : https://developers.google.com/chart/interactive/docs/gallery/piechart\n", "pie_lang.chart.options[:is3D] = true" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pie_lang.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.3.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.3.1" } }, "nbformat": 4, "nbformat_minor": 2 }