{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "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": {}, "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": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = [\n", " ['Year', 'Sales', 'Expenses'],\n", " ['2013', 1000, 400],\n", " ['2014', 1170, 460],\n", " ['2015', 660, 1120],\n", " ['2016', 1030, 540]\n", " ]\n", "area_chart_table = Daru::View::Table.new(data, {}, class_chart: 'Chartwrapper')\n", "area_chart_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "area_chart_options = {\n", " type: :area\n", "}\n", "area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, class_chart: 'ChartWrapper')\n", "area_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "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", "\n", "line_basic_chart = Daru::View::Plot.new(data, line_basic_options, class_chart: 'Chartwrapper')\n", "line_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "area_chart_options = {\n", " type: :area,\n", " view: {columns: [0, 1]}\n", "}\n", "area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, class_chart: 'ChartWrapper')\n", "area_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "area_chart_options = {\n", " type: :area,\n", " view: {columns: [1, 2]}\n", "}\n", "area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, class_chart: 'ChartWrapper')\n", "area_chart_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='\n", "table = Daru::View::Table.new(data_str, {width: 500}, class_chart: 'Chartwrapper')\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='\n", "table = Daru::View::Plot.new(data_str, {width: 500}, class_chart: 'Chartwrapper')\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='\n", "table = Daru::View::Plot.new(data_str, {width: 500, view: {columns: [0, 1]}}, class_chart: 'Chartwrapper')\n", "table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "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", "
City2010 Population
0New York City, NY8175000
1Los Angeles, CA3792000
2Chicago, IL2695000
3Houston, TX2099000
4Philadelphia, PA1526000
" ], "text/plain": [ "#\n", " City 2010 Popul\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": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['City', '2010 Population',]\n", "data_rows = [\n", "['New York City, NY', 8175000],\n", "['Los Angeles, CA', 3792000],\n", "['Chicago, IL', 2695000],\n", "['Houston, TX', 2099000],\n", "['Philadelphia, PA', 1526000]\n", "]\n", "df_city_pop = Daru::DataFrame.rows(data_rows)\n", "df_city_pop.vectors = idx\n", "df_city_pop" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic_table = Daru::View::Table.new(df_city_pop, {}, class_chart: 'Chartwrapper')\n", "bar_basic_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic_options = {\n", " title: 'Population of Largest U.S. Cities',\n", " type: :bar\n", "}\n", "bar_basic_chart = Daru::View::Plot.new(df_city_pop, bar_basic_options, class_chart: 'Chartwrapper')\n", "bar_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic_options = {\n", " title: 'Population of Largest U.S. Cities',\n", " type: :column\n", "}\n", "bar_basic_chart = Daru::View::Plot.new(bar_basic_table.table, bar_basic_options, class_chart: 'Chartwrapper')\n", "bar_basic_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bar_basic_table = Daru::View::Table.new(df_city_pop, {view: {columns: [0]}}, class_chart: 'Chartwrapper')\n", "bar_basic_table.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query_string = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'\n", "data_spreadsheet = 'https://docs.google.com/spreadsheets/d/1XWJLkAwch5GXAt_7zOFDcg8Wm8Xv29_8PWuuW15qmAE/gviz/tq?gid=0&headers=1&tq='\n", "data_spreadsheet << query_string\n", "table_spreadsheet = Daru::View::Table.new(data_spreadsheet, {width: 800}, class_chart: 'Chartwrapper')\n", "table_spreadsheet.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.4.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.4.1" } }, "nbformat": 4, "nbformat_minor": 2 }