Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google_charts

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google_charts

  • 2.0.0.alpha.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

GoogleCharts is a ruby wrapper to the Google Chart API (http://code.google.com/apis/charttools/)

Summary

For now, the plugin supports the following charts:

  • pie chart
  • line chart
  • bar chart
  • column chart
  • area chart

Basically, you can give the chart all the options you would give a GoogleChart when using the Google library: height, width, title, and so on...

For a detailed description of which options to use visit the Google Visualization API and check out the charts there: http://code.google.com/apis/visualization/documentation/gallery.html

Installation

System wide:

gem install google_charts

Or in your Gemfile:

gem 'google_charts'

Usage

GoogleCharts is based on a collection of elements. Usually they are records from the database, but can also just be an array.

The following Stock class is a Mongoid document and used to keep track of how much we have of any product in our online store. All we need is the product's name and the amount. For simplicity, we'll skip any default values or validations.

class Stock
  include Mongoid::Document

  field :name,    type: String
  field :amount,  type: Integer
end

Now, let's supply some data for our store.

Stock.create name: "Apple",  amount: 10
Stock.create name: "Pear",   amount: 5
Stock.create name: "Banana", amount: 1

Example: Pie chart

In order to figure out how much we have of any product, all we need to do is:

<%= pie_chart Stock.all do |c| %>
  <% c.title "Total Stock" %>

  <% c.label "Name",    :name %>
  <% c.value "Amount",  :amount %>
<% end %>

Example: Pie chart with block parameters for label and value

In order to dynamically display labels or values within a chart, you may also pass a block:

<%= pie_chart Stock.all do |c| %>
  <% c.title "Total Stock" %>

  <% c.label("Name")        { |s| "#{s.name} (percent)" } %>
  <% c.value("Percentage")  { |s| s.amount / Stock.sum(:amount) * 100 } %>
<% end %>

NOTE: I know that Stock.sum(:amount) is not good practice, but it serves the example.

Copyright © 2010 - 2012 Rudolf Schmidt, released under the MIT license.

FAQs

Package last updated on 09 Feb 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc