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]:
Daru::View.plotting_library = :googlecharts
Out[2]:
:googlecharts
In [3]:
idx = Daru::Index.new ['Topping', 'Slices']
data_rows = [
          ['Mushrooms', 1],
          ['Onions', 1],
          ['Olives', 2],
          ['Zucchini', 2],
          ['Pepperoni', 1]
]
df_sarah = Daru::DataFrame.rows(data_rows)
df_sarah.vectors = idx
df_sarah
Out[3]:
Daru::DataFrame(5x2)
Topping Slices
0 Mushrooms 1
1 Onions 1
2 Olives 2
3 Zucchini 2
4 Pepperoni 1
In [4]:
options = {
  type: :pie,
  title:'How Much Pizza Sarah Ate Last Night',
  width:400,
  height:300}
pizza_sarah = Daru::View::Plot.new(df_sarah, options)
pizza_sarah.show_in_iruby
Out[4]:
In [5]:
idx = Daru::Index.new ['Topping', 'Slices']
data_rows = [
          ['Mushrooms', 2],
          ['Onions', 2],
          ['Olives', 2],
          ['Zucchini', 0],
          ['Pepperoni', 3]
]
df_anthony = Daru::DataFrame.rows(data_rows)
df_anthony.vectors = idx
df_anthony
Out[5]:
Daru::DataFrame(5x2)
Topping Slices
0 Mushrooms 2
1 Onions 2
2 Olives 2
3 Zucchini 0
4 Pepperoni 3
In [6]:
options = {
  type: :pie,
  title:'How Much Pizza Anthony Ate Last Night',
  width:400,
  height:300}
pizza_anthony = Daru::View::Plot.new(df_anthony, options)
pizza_anthony.show_in_iruby
Out[6]:
In [7]:
combined_pizza = Daru::View::PlotList.new([pizza_sarah, pizza_anthony])
combined_pizza.show_in_iruby
Out[7]:
In [8]:
pizza_sarah_table = Daru::View::Table.new(df_sarah)
combined = Daru::View::PlotList.new([pizza_sarah_table, pizza_sarah])
combined.show_in_iruby
Out[8]:
In [9]:
pizza_anthony_table = Daru::View::Table.new(df_anthony)
combined = Daru::View::PlotList.new([pizza_anthony_table, pizza_anthony])
combined.show_in_iruby
Out[9]:
In [10]:
pizza_sarah_table = Daru::View::Table.new(df_sarah)
pizza_anthony_table = Daru::View::Table.new(df_anthony)
combined_table = Daru::View::PlotList.new([pizza_sarah_table, pizza_sarah, pizza_anthony_table, pizza_anthony])
combined_table.show_in_iruby
Out[10]:
In [11]:
options = {
  type: :bar,
  title:'How Much Pizza Sarah Ate Last Night',
  width:400,
  height:300
}
pizza_sarah_bar = Daru::View::Plot.new(df_sarah, options)
combined = Daru::View::PlotList.new([pizza_sarah, pizza_sarah_bar])
combined.show_in_iruby
Out[11]:
In [12]:
options_column = {
  type: :column,
  title:'How Much Pizza Sarah Ate Last Night',
  width:400,
  height:300
}
pizza_sarah_column = Daru::View::Plot.new(df_sarah, options_column)
combined = Daru::View::PlotList.new([pizza_sarah, pizza_sarah_column, pizza_sarah_bar])
combined.show_in_iruby
Out[12]:
In [13]:
options_hc = {
  chart: {
    type: 'pie'
  },
  title: {
    text: 'How Much Pizza Sarah Ate Last Night'
  },
  adapter: 'highcharts'
}
pizza_sarah_hc = Daru::View::Plot.new(df_sarah, options_hc)
pizza_sarah_hc.init_iruby
combined = Daru::View::PlotList.new([pizza_sarah, pizza_sarah_hc])
combined.show_in_iruby
Out[13]:
In [14]:
options_bar_hc = {
  chart: {
    type: 'bar'
  },
  title: {
    text: 'How Much Pizza Sarah Ate Last Night'
  },
  adapter: 'highcharts'
}
pizza_sarah_bar_hc = Daru::View::Plot.new(df_sarah, options_bar_hc)
combined = Daru::View::PlotList.new([pizza_sarah_bar, pizza_sarah_bar_hc])
combined.show_in_iruby
Out[14]:
In [15]:
combined_pizzas = Daru::View::PlotList.new([pizza_sarah, pizza_sarah_hc, pizza_sarah_bar, pizza_sarah_bar_hc])
combined_pizzas.show_in_iruby
Out[15]:
In [16]:
dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category
bar_graph1 = Daru::View::Plot.new(dv, type: :bar, adapter: :nyaplot)
bar_graph1.init_iruby
combined = Daru::View::PlotList.new([pizza_sarah, bar_graph1])
combined.show_in_iruby
Out[16]:
In [17]:
dv = Daru::Vector.new ['III']*10 + ['II']*5 + ['I']*5, type: :category, categories: ['I', 'II', 'III']
bar_graph2 = Daru::View::Plot.new(dv, type: :bar, adapter: :nyaplot)
bar_combined = Daru::View::PlotList.new([bar_graph1, bar_graph2])
bar_combined.show_in_iruby
Out[17]:
In [18]:
df = Daru::DataFrame.new(
  {
    data1: ['Website visits', 'Downloads', 'Requested price list', 'Invoice sent', 'Finalized'],
    data2: [15654, 4064, 1987, 976, 846]
  }
)
Out[18]:
Daru::DataFrame(5x2)
data1 data2
0 Website visits 15654
1 Downloads 4064
2 Requested price list 1987
3 Invoice sent 976
4 Finalized 846
In [19]:
opts_funnel = {
  chart: {
      type: 'funnel'
  },
  title: {
      text: 'Sales funnel'
  },
  plotOptions: {
      series: {
          dataLabels: {
              enabled: true,
              format: '<b>{point.name}</b> ({point.y:,.0f})',
              color: "(Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'".js_code,
              softConnector: true
          },
          center: ['40%', '50%'],
          neckWidth: '30%',
          neckHeight: '25%',
          width: '80%'
      }
  },
  legend: {
      enabled: false
  },
  adapter: 'highcharts'
}

opts_pyramid = {
  chart: {
      type: 'pyramid'
  },
  title: {
      text: 'Sales pyramid',
      x: -50
  },
  plotOptions: {
      series: {
          dataLabels: {
              enabled: true,
              format: '<b>{point.name}</b> ({point.y:,.0f})',
              softConnector: true
          },
          center: ['40%', '50%'],
          width: '80%'
      }
  },
  legend: {
      enabled: false
  },
  adapter: 'highcharts'
}

funnel_hc = Daru::View::Plot.new(df, opts_funnel, modules: ['modules/funnel'])
pyramid_hc = Daru::View::Plot.new(df, opts_pyramid)

combined = Daru::View::PlotList.new([funnel_hc, pyramid_hc])
combined.show_in_iruby
Out[19]:
In [ ]: