{ "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": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Default chart type is Line.\n", "line_basic_chart = Daru::View::Plot.new(df_sale_exp)\n", "line_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_basic_options = {\n", " title: 'Company Performance',\n", " curveType: 'function',\n", " legend: { position: 'bottom' }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_basic_chart = Daru::View::Plot.new(df_sale_exp, line_basic_options)\n", "line_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[400, 460, 1120, 540]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Adding another series\n", "df_sale_exp['Expense'] = [400, 460, 1120, 540]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(4x3) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
YearSalesExpense
020041000400
120051170460
220066601120
320071030540
" ], "text/plain": [ "#\n", " Year Sales Expense\n", " 0 2004 1000 400\n", " 1 2005 1170 460\n", " 2 2006 660 1120\n", " 3 2007 1030 540" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_sale_exp" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_basic_options = {\n", " title: 'Company Performance',\n", " curveType: 'function',\n", " legend: { position: 'bottom' }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_basic_chart = Daru::View::Plot.new(df_sale_exp, line_basic_options)\n", "line_basic_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**TODO: Material Line Charts feature is not present in google_visualr. Add this in daru-view **" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "data = [\n", " ['Month', 'Average Temperature', 'Average Hours of Daylight'],\n", " [DateTime.new(2014, 1).to_date, 0.4, 8.7],\n", " [DateTime.new(2014, 2).to_date, 0.5, 12],\n", " [DateTime.new(2014, 3).to_date, 2.9, 15.3],\n", " [DateTime.new(2014, 4).to_date, 6.3, 18.6],\n", " [DateTime.new(2014, 5).to_date, 9, 20.9],\n", " [DateTime.new(2014, 6).to_date, 10.6, 19.8],\n", " [DateTime.new(2014, 7).to_date, 10.3, 16.6],\n", " [DateTime.new(2014, 8).to_date, 7.4, 13.3],\n", " [DateTime.new(2014, 9).to_date, 4.4, 9.9],\n", " [DateTime.new(2014, 10).to_date, 1.1, 6.6],\n", " [DateTime.new(2014, 11).to_date, -0.2, 4.5]\n", " ]\n", "temp_table = Daru::View::Table.new(data)\n", "temp_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DateTime.new(2001,2,3).to_date" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DateTime.new(2001,2,3)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dualY_options = {\n", " title: 'Company Performance',\n", " curveType: 'function',\n", " legend: { position: 'bottom' }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dualY_chart = Daru::View::Plot.new(temp_table, line_dualY_options)\n", "line_dualY_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dualY_options = {\n", "title: 'Average Temperatures and Daylight in Iceland Throughout the Year',\n", " width: 900,\n", " height: 500,\n", " # Gives each series an axis that matches the vAxes number below.\n", " series: {\n", " 0 => {targetAxisIndex: 0},\n", " 1 => {targetAxisIndex: 1}\n", " },\n", " vAxes: {\n", " # Adds titles to each axis.\n", " 0 => {title: 'Temps (Celsius)'},\n", " 1 => {title: 'Daylight'}\n", " },\n", "\n", " hAxis: {\n", " ticks: [ DateTime.new(2014, 1) , DateTime.new(2014, 2) , DateTime.new(2014, 3) , DateTime.new(2014, 4) , \n", " DateTime.new(2014, 5) , DateTime.new(2014, 6) , DateTime.new(2014, 7) , DateTime.new(2014, 8) , DateTime.new(2014, 9) , \n", " DateTime.new(2014, 10) , DateTime.new(2014, 11) , DateTime.new(2014, 12) , \n", " ]\n", " },\n", " vAxis: {\n", " viewWindow: {\n", " max: 30\n", " }\n", " }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dualY_chart = Daru::View::Plot.new(temp_table, line_dualY_options)\n", "line_dualY_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Top-X Charts" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "data = [\n", " ['Day', 'Guardians of the Galaxy', 'The Avengers', 'Transformers: Age of Extinction'],\n", " [1, 37.8, 80.8, 41.8],\n", " [2, 30.9, 69.5, 32.4],\n", " [3, 25.4, 57, 25.7],\n", " [4, 11.7, 18.8, 10.5],\n", " [5, 11.9, 17.6, 10.4],\n", " [6, 8.8, 13.6, 7.7],\n", " [7, 7.6, 12.3, 9.6],\n", " [8, 12.3, 29.2, 10.6],\n", " [9, 16.9, 42.9, 14.8],\n", " [10, 12.8, 30.9, 11.6],\n", " [11, 5.3, 7.9, 4.7],\n", " [12, 6.6, 8.4, 5.2],\n", " [13, 4.8, 6.3, 3.6],\n", " [14, 4.2, 6.2, 3.4]\n", " ]\n", "box_office_table = Daru::View::Table.new(data)\n", "box_office_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_topX_options = {\n", " type: :line\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_topX_chart = Daru::View::Plot.new(box_office_table, line_topX_options)\n", "line_topX_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_topX_options = {\n", "\n", " title: 'Box Office Earnings in First Two Weeks of Opening',\n", "\n", " width: 900,\n", " height: 500,\n", " # FixMe: might be other syntax for it.\n", " vAxes: {\n", " 0 => {side: 'top'}\n", " }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_topX_chart = Daru::View::Plot.new(box_office_table, line_topX_options)\n", "line_topX_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "data = [\n", " ['X', 'Dogs', 'Cats'],\n", " [0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5],\n", " [6, 11, 3], [7, 27, 19], [8, 33, 25], [9, 40, 32], [10, 32, 24], [11, 35, 27],\n", " [12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],\n", " [18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],\n", " [24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],\n", " [30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],\n", " [36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],\n", " [42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],\n", " [48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],\n", " [54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],\n", " [60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],\n", " [66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]\n", " ]\n", "dog_cat_table = Daru::View::Table.new(data, pageSize: 8)\n", "dog_cat_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dog_cat_options = {\n", " \n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options)\n", "line_dog_cat_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 69, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dog_cat_options = {\n", " hAxis: {\n", " title: 'Time'\n", " },\n", " vAxis: {\n", " title: 'Popularity'\n", " },\n", " colors: ['#a52714', '#097138'],\n", " crosshair: {\n", " color: '#000',\n", " trigger: 'selection'\n", " }\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options)\n", "# click to see the crosshair\n", "line_dog_cat_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 74, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dog_cat_options = {\n", " hAxis: {\n", " title: 'Time'\n", " },\n", " vAxis: {\n", " title: 'Popularity'\n", " },\n", " colors: ['#AB0D06', '#007329'],\n", " trendlines: {\n", " 0 => {type: 'exponential', color: '#333', opacity: 1},\n", " 1 => {type: 'linear', color: '#111', opacity: 0.3}\n", " },\n", " height: 500\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options)\n", "\n", "line_dog_cat_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dog_cat_options = {\n", "hAxis: {\n", " title: 'Time'\n", " },\n", " vAxis: {\n", " title: 'Popularity'\n", " },\n", " colors: ['#a52714', '#097138'],\n", " series: {\n", " 0 => {\n", " lineWidth: 10,\n", " lineDashStyle: [5, 1, 5]\n", " },\n", " 1 => {\n", " lineWidth: 5,\n", " lineDashStyle: [7, 2, 4, 3]\n", " }\n", " },\n", " height: 500\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options)\n", "\n", "line_dog_cat_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line_dog_cat_options = {\n", " hAxis: {\n", " title: 'Time',\n", " textStyle: {\n", " color: '#01579b',\n", " fontSize: 20,\n", " fontName: 'Arial',\n", " bold: true,\n", " italic: true\n", " },\n", " titleTextStyle: {\n", " color: '#01579b',\n", " fontSize: 16,\n", " fontName: 'Arial',\n", " bold: false,\n", " italic: true\n", " }\n", " },\n", " vAxis: {\n", " title: 'Popularity',\n", " textStyle: {\n", " color: '#1a237e',\n", " fontSize: 24,\n", " bold: true\n", " },\n", " titleTextStyle: {\n", " color: '#1a237e',\n", " fontSize: 24,\n", " bold: true\n", " }\n", " },\n", " colors: ['#a52714', '#097138'],\n", " height: 500\n", "}\n", "# We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source\n", "line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options)\n", "\n", "line_dog_cat_chart.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 }