In [1]:
require 'daru/view'
Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.

Install the mechanize gem version ~>2.7.5 for using mechanize functions.
Out[1]:
true
In [2]:
Daru::View.plotting_library = :googlecharts
Out[2]:
:googlecharts
In [3]:
data = [
  ['Location', 'Parent', 'Market trade volume (size)', 'Market increase/decrease (color)'],
          ['Global',    nil,                 0,                               0],
          ['America',   'Global',             0,                               0],
          ['Europe',    'Global',             0,                               0],
          ['Asia',      'Global',             0,                               0],
          ['Australia', 'Global',             0,                               0],
          ['Africa',    'Global',             0,                               0],
          ['Brazil',    'America',            11,                              10],
          ['USA',       'America',            52,                              31],
          ['Mexico',    'America',            24,                              12],
          ['Canada',    'America',            16,                              -23],
          ['France',    'Europe',             42,                              -11],
          ['Germany',   'Europe',             31,                              -2],
          ['Sweden',    'Europe',             22,                              -13],
          ['Italy',     'Europe',             17,                              4],
          ['UK',        'Europe',             21,                              -5],
          ['China',     'Asia',               36,                              4],
          ['Japan',     'Asia',               20,                              -12],
          ['India',     'Asia',               40,                              63],
          ['Laos',      'Asia',               4,                               34],
          ['Mongolia',  'Asia',               1,                               -5],
          ['Israel',    'Asia',               12,                              24],
          ['Iran',      'Asia',               18,                              13],
          ['Pakistan',  'Asia',               11,                              -52],
          ['Egypt',     'Africa',             21,                              0],
          ['S. Africa', 'Africa',             30,                              43],
          ['Sudan',     'Africa',             12,                              2],
          ['Congo',     'Africa',             10,                              12],
          ['Zaire',     'Africa',             8,                               10]
        ]

treemap_table = Daru::View::Table.new(data, pageSize: 8)
treemap_table.show_in_iruby
Out[3]:
In [4]:
treemap_basic_options = {
          type: :treemap,
}
# We can pass dataframe/vector/data array/ google datatable or Daru-view Table  as data source
treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)
treemap_basic_chart.show_in_iruby
Out[4]:
In [5]:
treemap_basic_options = {
          type: :treemap,
          minColor: '#f00',
          midColor: '#ddd',
          maxColor: '#0d0',
          headerHeight: 15,
          fontColor: 'black',
          showScale: true
}
# We can pass dataframe/vector/data array/ google datatable or Daru-view Table  as data source
treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)
treemap_basic_chart.show_in_iruby
Out[5]:

Highlights

In [6]:
treemap_basic_options = {
          type: :treemap,
highlightOnMouseOver: true,
        maxDepth: 1,
        maxPostDepth: 2,
        minHighlightColor: '#8c6bb1',
        midHighlightColor: '#9ebcda',
        maxHighlightColor: '#edf8fb',
        minColor: '#009688',
        midColor: '#f7f7f7',
        maxColor: '#ee8100',
        headerHeight: 15,
        showScale: true,
        height: 500,
        useWeightedAverageForAggregation: true
}
# We can pass dataframe/vector/data array/ google datatable or Daru-view Table  as data source
treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)
treemap_basic_chart.show_in_iruby
Out[6]:

Tooltips

In [7]:
js_method = <<-EOJS
function showStaticTooltip(row, size, value) {
    return '<div style='background:#fd9; padding:10px; border-style:solid'>' +
           'Read more about the <a href='http://en.wikipedia.org/wiki/Kingdom_(biology)'>kingdoms of life</a>.</div>';
  }
EOJS
treemap_basic_options = {
          type: :treemap,
    minColor: '#e7711c',
    midColor: '#fff',
    maxColor: '#4374e0',
    showScale: true,
#     generateTooltip: js_method
}
# We can pass dataframe/vector/data array/ google datatable or Daru-view Table  as data source
treemap_basic_chart = Daru::View::Plot.new(treemap_table.table, treemap_basic_options)
treemap_basic_chart.show_in_iruby
Out[7]: