require 'daru/view'
true
Daru::View.plotting_library = :googlecharts
:googlecharts
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
Topping | Slices | |
---|---|---|
0 | Mushrooms | 1 |
1 | Onions | 1 |
2 | Olives | 2 |
3 | Zucchini | 2 |
4 | Pepperoni | 1 |
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
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
Topping | Slices | |
---|---|---|
0 | Mushrooms | 2 |
1 | Onions | 2 |
2 | Olives | 2 |
3 | Zucchini | 0 |
4 | Pepperoni | 3 |
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
combined_pizza = Daru::View::PlotList.new([pizza_sarah, pizza_anthony])
combined_pizza.show_in_iruby
pizza_sarah_table = Daru::View::Table.new(df_sarah)
combined = Daru::View::PlotList.new([pizza_sarah_table, pizza_sarah])
combined.show_in_iruby
pizza_anthony_table = Daru::View::Table.new(df_anthony)
combined = Daru::View::PlotList.new([pizza_anthony_table, pizza_anthony])
combined.show_in_iruby
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
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
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
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
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
combined_pizzas = Daru::View::PlotList.new([pizza_sarah, pizza_sarah_hc, pizza_sarah_bar, pizza_sarah_bar_hc])
combined_pizzas.show_in_iruby
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
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
df = Daru::DataFrame.new(
{
data1: ['Website visits', 'Downloads', 'Requested price list', 'Invoice sent', 'Finalized'],
data2: [15654, 4064, 1987, 976, 846]
}
)
data1 | data2 | |
---|---|---|
0 | Website visits | 15654 |
1 | Downloads | 4064 |
2 | Requested price list | 1987 |
3 | Invoice sent | 976 |
4 | Finalized | 846 |
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