Project

chart_js

0.01
No commit activity in last 3 years
No release in over 3 years
A simple ruby DSL to build responive charts for the web using Chart.js
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 0.12
~> 13.0
~> 3.0
 Project Readme

Chart JS

Chart JS is a simple yet flexible JavaScript charting library. This gem is a Ruby Domain Specific Language which allows you to easily build charts without touching a single line of JavaScript or HTML.

Installation

$ gem install chart_js

Usage

A simple example to generate a static html file.

require "chart_js"

ChartJS.line do
  file "example.html"
  data do
    labels ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    dataset "Cats" do
      color :random
      data [12, 19, 3, 5, 2, 3]
    end 
    dataset "Dogs" do
      color :random
      data [10, 12, 3, 4, 5, 3]
    end 
  end
end

Web Framework Integration

chart_js plays well with others.

require "chart_js"
require "sinatra"

get "/" do
  chart = ChartJS.line do
    data do
      labels ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
      dataset "Cats" do
        color :random
        data [12, 19, 3, 5, 2, 3]
      end 
      dataset "Dogs" do
        color :random
        data [10, 12, 3, 4, 5, 3]
      end 
    end
  end
  chart.to_html
end

Screenshot

example

License

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