require 'daru/view'
true
Daru::View.plotting_library = :googlecharts
:googlecharts
data = [
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]
pie_chart_table = Daru::View::Table.new(data)
pie_chart_table.show_in_iruby
pie_chart_options = {
type: :pie, height: 400, title: 'My Daily Activities'
}
pie_chart_chart = Daru::View::Plot.new(pie_chart_table.table, pie_chart_options)
pie_chart_chart.show_in_iruby
pie_chart3D_options = {
type: :pie, height: 400, title: 'My Daily Activities', is3D: true
}
pie_chart3D = Daru::View::Plot.new(pie_chart_table.table, pie_chart3D_options)
pie_chart3D.show_in_iruby
pie_chart_dount_options = {
type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.4,
}
pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)
pie_chart_dount.show_in_iruby
pie_chart_dount_options = {
type: :pie, height: 400, title: 'My Daily Activities',pieHole: 0.5,
pieSliceTextStyle: {
color: 'black',
},
legend: 'none'
}
pie_chart_dount = Daru::View::Plot.new(pie_chart_table.table, pie_chart_dount_options)
pie_chart_dount.show_in_iruby
data = [
['Language', 'Speakers (in millions)'],
['German', 5.85],
['French', 1.66],
['Italian', 0.316],
['Romansh', 0.0791]
]
pie_chart_rotate_table = Daru::View::Table.new(data)
pie_chart_rotate_table.show_in_iruby
pie_chart_rotate_options = {
type: :pie, height: 500
}
pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)
pie_chart_rotate_dount.show_in_iruby
pie_chart_rotate_options = {
legend: 'none',
pieSliceText: 'label',
title: 'Swiss Language Use (100 degree rotation)',
pieStartAngle: 100,type: :pie, height: 500
}
pie_chart_rotate_dount = Daru::View::Plot.new(pie_chart_rotate_table.table, pie_chart_rotate_options)
pie_chart_rotate_dount.show_in_iruby
data = [
['Language', 'Speakers (in millions)'],
['Assamese', 13], ['Bengali', 83], ['Bodo', 1.4],
['Dogri', 2.3], ['Gujarati', 46], ['Hindi', 300],
['Kannada', 38], ['Kashmiri', 5.5], ['Konkani', 5],
['Maithili', 20], ['Malayalam', 33], ['Manipuri', 1.5],
['Marathi', 72], ['Nepali', 2.9], ['Oriya', 33],
['Punjabi', 29], ['Sanskrit', 0.01], ['Santhali', 6.5],
['Sindhi', 2.5], ['Tamil', 61], ['Telugu', 74], ['Urdu', 52]
]
pie_chart_slice_table = Daru::View::Table.new(data, pageSize: 5)
pie_chart_slice_table.show_in_iruby
pie_chart_slice_options = {
type: :pie, height: 500
}
pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)
pie_chart_slice.show_in_iruby
pie_chart_slice_options = {
title: 'Indian Language Use',
legend: 'none',
pieSliceText: 'label',
slices: { 4 => {offset: 0.2},
12 => {offset: 0.3},
14 => {offset: 0.4},
15 => {offset: 0.5},
},
type: :pie, height: 500
}
pie_chart_slice = Daru::View::Plot.new(pie_chart_slice_table.table, pie_chart_slice_options)
pie_chart_slice.show_in_iruby
idx = Daru::Index.new ['Pac Man', 'Percentage']
data_rows = [
['', 75],
['', 25]]
df_pac_man = Daru::DataFrame.rows(data_rows)
df_pac_man.vectors = idx
df_pac_man
Pac Man | Percentage | |
---|---|---|
0 | 75 | |
1 | 25 |
pie_pac_chart = Daru::View::Plot.new(df_pac_man, type: :pie)
pie_pac_chart.show_in_iruby
opts = {
legend: 'none',
pieSliceText: 'none',
pieStartAngle: 135,
tooltip: { trigger: 'none' },
slices: {
0 => { color: 'yellow' },
1 => { color: 'transparent' }
},
type: :pie
}
pie_pac_chart = Daru::View::Plot.new(df_pac_man, opts)
pie_pac_chart.show_in_iruby
idx = Daru::Index.new ['Pizza', 'Populartiy']
data_rows = [
['Pepperoni', 33],
['Hawaiian', 26],
['Mushroom', 22],
['Sausage', 10], # Below limit.
['Anchovies', 9] # Below limit.
]
df_pizza = Daru::DataFrame.rows(data_rows)
df_pizza.vectors = idx
df_pizza
Pizza | Populartiy | |
---|---|---|
0 | Pepperoni | 33 |
1 | Hawaiian | 26 |
2 | Mushroom | 22 |
3 | Sausage | 10 |
4 | Anchovies | 9 |
opts = {
title: 'Popularity of Types of Pizza',
sliceVisibilityThreshold: 0.2,
type: :pie, height: 400
}
pie_pizza = Daru::View::Plot.new(df_pizza, opts)
pie_pizza.show_in_iruby