Rubyist’s, so called Powerful Future Plotting library
Why only other languages have web app/Jupyter notebook plotting libraries? Need interactive plotting? No JavaScript code again, please! With daru-view, you get to plot Google charts, Highcharts, HighMaps, HighStock, Datatables, D3.js and compare them using only few a lines of Ruby. Amazing, Right?
In this blog we will be using daru gem for data analysis and daru-view to get the overview of the data. This gem doesn’t require knowledge of GoogleCharts, HighCharts, HighStock, HighMap, DataTables APIs, but having some knowledge will help to make custom/advance chats.
Let’s try
One of the main feature it you can try out code snippet in IRuby Notebook (just like IPython notebook for Python):
Require it:
require 'daru/view'
Highchart/HighMap/HighStock
Daru::View.plotting_library = :highcharts
# Simple line chart
@line_graph = Daru::View::Plot.new(
data=[43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
)
# to see graph in IRuby noteboook
@line_graph.show_in_iruby
For multiple series — line chart (after putting some options defined in HighChart):
Advance usage and articles:
- Github Repo: sciruby/daru-view
- IRUby notebook examples for line chart
- HighChart blog on daru-view
- HighChart blog on daru-view for Ruby web applications
- IRubyNotebook HighMap example
GoogleChart/Google DataTable/GeoMap
Now it is easy to use Google Charts/Tables/GeoMap in your Ruby web application and as well as in IRuby Notebook
In GoogleChart we have to provide point (x,y) for line chart, check the GoogleCHart API for more details, all the examples given in GoogleChart Site can be used directly in daru-view API:
Set the Google Chart as your plotting library:
Daru::View.plotting_library = :googlechartsdata = [
['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)# This is Google DataTable
temp_table.show_in_iruby# Optional customized title and chart options
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
Output :
Advance/Customized examples :
D3.js
daru-view used Nyaplot which provides charts using D3.js in Ruby
More examples :
DataTables.js
daru-view gem uses DataTables.js to import large size data in pieces, check the examples in below section link
daru-view in Any Ruby Webapplications like Rails, Sinatra, Nanoc, Hanami:
Demo daru-view in Ruby web app, give idea how to use it in any Ruby web application framework effectively.
Setup guide is written in README file: SciRuby/daru-view.
- Basic working example hosted here: sciruby.com/daru-view
Other important links to explore daru-view and use:
- All about daruy-view
- Why to use daru-view
- Powerful features of daru-view
- Design Pattern used in daru-view
- GSoC 2017 — blog posts — how it was designed from scratch
- GSoC 2018 — Progress report — New features added
- Paris Ruby Conf talk
- Future plans
Thanks everyone for reading. having so powerful features, daru-view is still in early stage. Open an issue if you find a bug in github while using it in your Ruby application which need interactive plots with minimal code
I will continue blogging, apploud on this article if you like it and stay tuned for updates: Twitter, Github, Instagram :)