In [1]:
require 'daru/view'
Out[1]:
true
In [2]:
Daru::View.plotting_library = :googlecharts
Out[2]:
:googlecharts
In [3]:
data = [
          ['Year', 'Sales', 'Expenses'],
          ['2013',  1000,      400],
          ['2014',  1170,      460],
          ['2015',  660,       1120],
          ['2016',  1030,      540]
  ]
area_chart_table = Daru::View::Table.new(data, {}, chart_class: 'Chartwrapper')
area_chart_table.show_in_iruby
Out[3]:
In [4]:
area_chart_options = {
  type: :area
}
area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, chart_class: 'ChartWrapper')
area_chart_chart.show_in_iruby
Out[4]:
In [5]:
line_basic_options = {
  title: 'Company Performance',
  curveType: 'function',
  legend: { position: 'bottom' }
}

line_basic_chart = Daru::View::Plot.new(data, line_basic_options, chart_class: 'Chartwrapper')
line_basic_chart.show_in_iruby
Out[5]:
In [6]:
area_chart_options = {
  type: :area,
  view: {columns: [0, 1]}
}
area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, chart_class: 'ChartWrapper')
area_chart_chart.show_in_iruby
Out[6]:
In [7]:
area_chart_options = {
  type: :area,
  view: {columns: [1, 2]}
}
area_chart_chart = Daru::View::Plot.new(area_chart_table.table, area_chart_options, chart_class: 'ChartWrapper')
area_chart_chart.show_in_iruby
Out[7]:
In [8]:
data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='
table = Daru::View::Table.new(data_str, {width: 500}, chart_class: 'Chartwrapper')
table.show_in_iruby
Out[8]:
In [9]:
data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='
table = Daru::View::Plot.new(data_str, {width: 500}, chart_class: 'Chartwrapper')
table.show_in_iruby
Out[9]:
In [10]:
data_str = 'https://docs.google.com/spreadsheets/d/1aXns2ch8y_rl9ZLxSYZIU5ewUB1ZNAg5O6iPLZLApZI/gviz/tq?header=1&tq='
table = Daru::View::Plot.new(data_str, {width: 500, view: {columns: [0, 1]}}, chart_class: 'Chartwrapper')
table.show_in_iruby
Out[10]:
In [11]:
idx = Daru::Index.new ['City', '2010 Population',]
data_rows = [
['New York City, NY', 8175000],
['Los Angeles, CA', 3792000],
['Chicago, IL', 2695000],
['Houston, TX', 2099000],
['Philadelphia, PA', 1526000]
]
df_city_pop = Daru::DataFrame.rows(data_rows)
df_city_pop.vectors = idx
df_city_pop
Out[11]:
Daru::DataFrame(5x2)
City 2010 Population
0 New York City, NY 8175000
1 Los Angeles, CA 3792000
2 Chicago, IL 2695000
3 Houston, TX 2099000
4 Philadelphia, PA 1526000
In [12]:
bar_basic_table = Daru::View::Table.new(df_city_pop, {}, chart_class: 'Chartwrapper')
bar_basic_table.show_in_iruby
Out[12]:
In [13]:
bar_basic_options = {
  title: 'Population of Largest U.S. Cities',
  type: :bar
}
bar_basic_chart = Daru::View::Plot.new(df_city_pop, bar_basic_options, chart_class: 'Chartwrapper')
bar_basic_chart.show_in_iruby
Out[13]:
In [14]:
bar_basic_options = {
  title: 'Population of Largest U.S. Cities',
  type: :column
}
bar_basic_chart = Daru::View::Plot.new(bar_basic_table.table, bar_basic_options, chart_class: 'Chartwrapper')
bar_basic_chart.show_in_iruby
Out[14]:
In [15]:
bar_basic_table = Daru::View::Table.new(df_city_pop, {view: {columns: [0]}}, chart_class: 'Chartwrapper')
bar_basic_table.show_in_iruby
Out[15]:
In [16]:
query_string = 'SELECT A, H, O, Q, R, U LIMIT 5 OFFSET 8'
data_spreadsheet = 'https://docs.google.com/spreadsheets/d/1XWJLkAwch5GXAt_7zOFDcg8Wm8Xv29_8PWuuW15qmAE/gviz/tq?gid=0&headers=1&tq='
data_spreadsheet << query_string
table_spreadsheet = Daru::View::Table.new(data_spreadsheet, {width: 800}, chart_class: 'Chartwrapper')
table_spreadsheet.show_in_iruby
Out[16]:
In [ ]: