Socket
Book a DemoInstallSign in
Socket

simple-gcharts

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-gcharts

0.1.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

Simple GCharts

Create Google Charts in your views using ruby, with no Javascript required. This library will serialize your data andautomatically load any required charts packages, and render your charts for you. Requires jQuery.

Example PieChart

class ActivitiesController < ActionController::Base
  def graphs
    @activities = {
      'Work' => 11,
      'Eat' => 2,
      'Commute' => 2,
      'Watch TV' => 2,
      'Sleep' => 7
    }
  end
end
# views/activities/graphs.html.erb
<%= google_chart :pie, ['Task', 'Hours per Day'], @activities.map { |k,v| [k, v] }, { title: 'My Daily Activities' } %>

Installation

Add this line to your application's Gemfile:

gem 'simple-gcharts'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple-gcharts

Add script to application.js (or appropriate page)

//= require jquery
//= require simple-gcharts

Usage

See the Google Charts Documentation for chart type descriptions and options.

google_chart

def google_chart type, headers, data, opts={}, chart_id="chart-#{SecureRandom.hex(10)}", parent_tag=:div
ArgumentDescription
typeThe type of chart (e.g. :line, see below)
headersThe column data. Can be column name or object
dataA 2-D array of data rows. headers and data combined are passed to arrayToDataTable()
optsOptions passed to chart.draw()
chart_idThe HTML id attribute to use for the chart
parent_tagThe tag used to wrap the child tags

Ruby can't make Javascript date objects, but fortunately Google Charts supports an alternate syntax for date and time datatypes. You can use chart_date_format to convert DateTime objects to the proper format.

def chart_date_format(datetime, time=false)
  if time
    datetime.strftime "Date(%Y, %m, %d, %H, %M, %S)"
  else
    datetime.strftime "Date(%Y, %m, %d)"
  end
end

Chart Types

Types
:annotation
:area
:bubble
:bar
:calendar
:candlestick
:column
:combo
:gantt
:gauge
:geochart
:histogram
:line
:map
:orgchart
:pie
:snakey
:scatter
:stepped
:table
:timeline
:treemap
:word

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 19 Jul 2016

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.