require 'daru/view' Daru::View.plotting_library = :googlecharts data = [ ['Year', 'Sales', 'Expenses'], ['2013', 1000, 400], ['2014', 1170, 460], ['2015', 660, 1120], ['2016', 1030, 540] ] user_option = { listeners: { page: "alert('The user is navigating to page ' + (e['page'] + 1));", select: "alert('A table row was selected');" } } column_chart_table = Daru::View::Table.new(data, {page: 'enable', pageSize: 2}, user_option) column_chart_table.show_in_iruby user_options = { listeners: { select: " var selection = chart.getSelection(); var selectedValue = data_table.getFormattedValue(selection[0].row, 0); alert('You selected ' + selectedValue + ' year');", # This will export the chart to PDF in web frameworks but in IRuby notebook, js dependency of jsPDF is not loaded properly. # ready: "var doc = new jsPDF(); # doc.addImage(chart.getImageURI(), 0, 0); # doc.save('chart.pdf');" } } column_chart = Daru::View::Plot.new(column_chart_table.table, { type: :column }, user_options) column_chart.show_in_iruby user_options = { listeners: { select: "alert('A table row was selected');" } } column_chart = Daru::View::Plot.new(column_chart_table.table, {type: :area}, user_options) column_chart.show_in_iruby