No commit activity in last 3 years
No release in over 3 years
Differs from original in that it uses the JSON gem to provide valid JSON.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 0
 Project Readme

Description¶ ↑

A Ruby interface to manipulate and populate data for Google Interactive Charts.

Example¶ ↑

require 'erb'
require 'rubygems'
require 'google_visualization'

include Google::Visualization

data_table = DataTable.new
data_table.add_column DataColumn.new(DataType::STRING, 'Task')
data_table.add_column DataColumn.new(DataType::NUMBER, 'Hours per Day')
data_table.add_row ['Work', 11]
data_table.add_row ['Eat', 2]
data_table.add_row ['Commute', 2]
data_table.add_row ['Watch TV', 2]
data_table.add_row ['Sleep', 7]

page = <<HTML
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1', {'packages':['piechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {
        // Create our data table.
        var data = new google.visualization.DataTable(<%= data_table.to_json %>);

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 400, height: 240, is3D: true, title: 'My Daily Activities'});
      }
    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>
HTML

template = ERB.new(page)
print template.result

Copyright¶ ↑

Copyright © 2010 Miguel Fonseca. See LICENSE for details.