GoogleVisualr - Geo Chart


Overview

An SVG-based map of a continent, region, or country with colors and values assigned to specific areas.

Values are displayed as a color scale, and you can specify optional hover text for regions.

Please refer to Google's documentation for details on Data Format and Configuration Options. However, Methods and Events are not implemented.


Example


Code

In your controller, create the data_table object, set new columns, add row values, then instantiate the chart with configuration options.

  # http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html#Example
  def geo_chart

    data_table = GoogleVisualr::DataTable.new
    data_table.new_column('string', 'Country')
    data_table.new_column('number', 'Popularity')
    data_table.add_rows(6)
    data_table.set_cell(0, 0, 'Germany'      )
    data_table.set_cell(0, 1, 200)
    data_table.set_cell(1, 0, 'United States')
    data_table.set_cell(1, 1, 300)
    data_table.set_cell(2, 0, 'Brazil'       )
    data_table.set_cell(2, 1, 400)
    data_table.set_cell(3, 0, 'Canada'       )
    data_table.set_cell(3, 1, 500)
    data_table.set_cell(4, 0, 'France'       )
    data_table.set_cell(4, 1, 600)
    data_table.set_cell(5, 0, 'RU'           )
    data_table.set_cell(5, 1, 700)

    opts   = { :width => 500, :height => 300 }
    @chart = GoogleVisualr::Interactive::GeoChart.new(data_table, opts)

  end

In your view, use the render_chart method to generate JavaScript, during rendering of the view.

  <div id='chart'></div>
  <%= render_chart @chart, 'chart' %>