require 'daru/view' Daru::View.plotting_library = :googlecharts idx = Daru::Index.new ['Year', 'Sales'] data_rows = [ ['2004', 1000], ['2005', 1170], ['2006', 660], ['2007', 1030] ] df_sale_exp = Daru::DataFrame.rows(data_rows) df_sale_exp.vectors = idx df_sale_exp # Default chart type is Line. line_basic_chart = Daru::View::Plot.new(df_sale_exp) line_basic_chart.show_in_iruby line_basic_options = { title: 'Company Performance', curveType: 'function', legend: { position: 'bottom' } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_basic_chart = Daru::View::Plot.new(df_sale_exp, line_basic_options) line_basic_chart.show_in_iruby # Adding another series df_sale_exp['Expense'] = [400, 460, 1120, 540] df_sale_exp line_basic_options = { title: 'Company Performance', curveType: 'function', legend: { position: 'bottom' } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_basic_chart = Daru::View::Plot.new(df_sale_exp, line_basic_options) line_basic_chart.show_in_iruby data = [ ['Month', 'Average Temperature', 'Average Hours of Daylight'], [DateTime.new(2014, 1).to_date, 0.4, 8.7], [DateTime.new(2014, 2).to_date, 0.5, 12], [DateTime.new(2014, 3).to_date, 2.9, 15.3], [DateTime.new(2014, 4).to_date, 6.3, 18.6], [DateTime.new(2014, 5).to_date, 9, 20.9], [DateTime.new(2014, 6).to_date, 10.6, 19.8], [DateTime.new(2014, 7).to_date, 10.3, 16.6], [DateTime.new(2014, 8).to_date, 7.4, 13.3], [DateTime.new(2014, 9).to_date, 4.4, 9.9], [DateTime.new(2014, 10).to_date, 1.1, 6.6], [DateTime.new(2014, 11).to_date, -0.2, 4.5] ] temp_table = Daru::View::Table.new(data) temp_table.show_in_iruby DateTime.new(2001,2,3).to_date DateTime.new(2001,2,3) line_dualY_options = { title: 'Company Performance', curveType: 'function', legend: { position: 'bottom' } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dualY_chart = Daru::View::Plot.new(temp_table, line_dualY_options) line_dualY_chart.show_in_iruby line_dualY_options = { title: 'Average Temperatures and Daylight in Iceland Throughout the Year', width: 900, height: 500, # Gives each series an axis that matches the vAxes number below. series: { 0 => {targetAxisIndex: 0}, 1 => {targetAxisIndex: 1} }, vAxes: { # Adds titles to each axis. 0 => {title: 'Temps (Celsius)'}, 1 => {title: 'Daylight'} }, hAxis: { ticks: [ DateTime.new(2014, 1) , DateTime.new(2014, 2) , DateTime.new(2014, 3) , DateTime.new(2014, 4) , DateTime.new(2014, 5) , DateTime.new(2014, 6) , DateTime.new(2014, 7) , DateTime.new(2014, 8) , DateTime.new(2014, 9) , DateTime.new(2014, 10) , DateTime.new(2014, 11) , DateTime.new(2014, 12) , ] }, vAxis: { viewWindow: { max: 30 } } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dualY_chart = Daru::View::Plot.new(temp_table, line_dualY_options) line_dualY_chart.show_in_iruby data = [ ['Day', 'Guardians of the Galaxy', 'The Avengers', 'Transformers: Age of Extinction'], [1, 37.8, 80.8, 41.8], [2, 30.9, 69.5, 32.4], [3, 25.4, 57, 25.7], [4, 11.7, 18.8, 10.5], [5, 11.9, 17.6, 10.4], [6, 8.8, 13.6, 7.7], [7, 7.6, 12.3, 9.6], [8, 12.3, 29.2, 10.6], [9, 16.9, 42.9, 14.8], [10, 12.8, 30.9, 11.6], [11, 5.3, 7.9, 4.7], [12, 6.6, 8.4, 5.2], [13, 4.8, 6.3, 3.6], [14, 4.2, 6.2, 3.4] ] box_office_table = Daru::View::Table.new(data) box_office_table.show_in_iruby line_topX_options = { type: :line } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_topX_chart = Daru::View::Plot.new(box_office_table, line_topX_options) line_topX_chart.show_in_iruby line_topX_options = { title: 'Box Office Earnings in First Two Weeks of Opening', width: 900, height: 500, # FixMe: might be other syntax for it. vAxes: { 0 => {side: 'top'} } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_topX_chart = Daru::View::Plot.new(box_office_table, line_topX_options) line_topX_chart.show_in_iruby data = [ ['X', 'Dogs', 'Cats'], [0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5], [6, 11, 3], [7, 27, 19], [8, 33, 25], [9, 40, 32], [10, 32, 24], [11, 35, 27], [12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40], [18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49], [24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45], [30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57], [36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57], [42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62], [48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62], [54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60], [60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61], [66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72] ] dog_cat_table = Daru::View::Table.new(data, pageSize: 8) dog_cat_table.show_in_iruby line_dog_cat_options = { } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options) line_dog_cat_chart.show_in_iruby line_dog_cat_options = { hAxis: { title: 'Time' }, vAxis: { title: 'Popularity' }, colors: ['#a52714', '#097138'], crosshair: { color: '#000', trigger: 'selection' } } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options) # click to see the crosshair line_dog_cat_chart.show_in_iruby line_dog_cat_options = { hAxis: { title: 'Time' }, vAxis: { title: 'Popularity' }, colors: ['#AB0D06', '#007329'], trendlines: { 0 => {type: 'exponential', color: '#333', opacity: 1}, 1 => {type: 'linear', color: '#111', opacity: 0.3} }, height: 500 } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options) line_dog_cat_chart.show_in_iruby line_dog_cat_options = { hAxis: { title: 'Time' }, vAxis: { title: 'Popularity' }, colors: ['#a52714', '#097138'], series: { 0 => { lineWidth: 10, lineDashStyle: [5, 1, 5] }, 1 => { lineWidth: 5, lineDashStyle: [7, 2, 4, 3] } }, height: 500 } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options) line_dog_cat_chart.show_in_iruby line_dog_cat_options = { hAxis: { title: 'Time', textStyle: { color: '#01579b', fontSize: 20, fontName: 'Arial', bold: true, italic: true }, titleTextStyle: { color: '#01579b', fontSize: 16, fontName: 'Arial', bold: false, italic: true } }, vAxis: { title: 'Popularity', textStyle: { color: '#1a237e', fontSize: 24, bold: true }, titleTextStyle: { color: '#1a237e', fontSize: 24, bold: true } }, colors: ['#a52714', '#097138'], height: 500 } # We can pass dataframe/vector/data array/ google datatable or Daru-view Table as data source line_dog_cat_chart = Daru::View::Plot.new(dog_cat_table.table, line_dog_cat_options) line_dog_cat_chart.show_in_iruby