Giter Club home page Giter Club logo

chart's Introduction

Chart

See an example on heroku (Example Source Code)

Chart ships with the following awesome charts:

Chart

The motivation for making chart

I was reading up on rails engine and decided to test out my new knowledge by making a gem. As my previous project involves making multiple charts, I understand the pain of having duplicate data structure and functions in javascript and ruby just for the different charts.

Chart is my solution to quickly add Javascript/HTML chart into rails. You can write coffeescript/javascript to further interact with the rendered chart. Chart is inspired by another awesome gem chartkick

The limitation of chart is that it generates in-line javascript and it does not aim to be a 100% wrapper for all chart.

Chart works with Sprockets and your asset pipeline.

Several flavours to choose from.

ChartJS (MIT License)

  • Bar Chart <%= bar :id_of_your_chart, size, data %>
  • Line Chart <%= line :id, size, data %>
  • Pie Chart <%= pie :id, size, data %>
  • Radar Chart <%= radar :id, size, data %>

NVD3 (MIT License)

  • Box Plot <%= boxplot :id, size, data %>
  • Discrete Bar <%= discrete_bar :id, size, data %>
  • Horizontal Grouped Bar <%= horizontal_grouped_bar :id, size, data %>

Google Chart (Open Source)

  • Bar Chart <%= gBar :id, size, data %>
  • Line Chart <%= gLine :id, size, data %>
  • Pie Chart <%= gPie :id, size, data %>

Highchart (Free for Personal usage but paid for Commercial)

  • Bar Chart <%= hBar %>
  • Line Chart <%= hLine %>
  • Pie Chart <%= hPie %>
  • Area Chart <%= hArea %>

Installation

Add this line to your application's Gemfile:

gem 'chart'

At Application.js, write //= require chart after turbolinks. Only require the chart if you need them.

//= require turbolinks
//= require chart
//= require chart2 (not compatible with chart 1.1.1)
//= require nvd3
//= require google
//= require highcharts

At Application.css, write *= require nvd3

*= require_tree .
*= require nvd3

Example Usage

Chart

At your View

<%= pie :pie_chart, @pieSize, @pieData%>

At your Controller

@pieSize = {
    :height => 500,
    :width => 500
  }

  @pieData = [
        {
          value: 300,
          color:"#F7464A",
          highlight: "#FF5A5E",
          label: "Red"
        },
        {
          value: 50,
          color: "#46BFBD",
          highlight: "#5AD3D1",
          label: "Green"
        },
        {
          value: 100,
          color: "#FDB45C",
          highlight: "#FFC870",
          label: "Yellow"
        },
        {
          value: 40,
          color: "#949FB1",
          highlight: "#A8B3C5",
          label: "Grey"
        },
        {
          value: 120,
          color: "#4D5360",
          highlight: "#616774",
          label: "Dark Grey"
        }

      ].to_json

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake false to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ytbryan/chart. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

Contact

๐Ÿ“ฎ Bryan Lim [email protected]

chart's People

Contributors

ytbryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

chart's Issues

Data example for Radar?

Hello, sample data renders JS error on radar types.

nvd3.self-f952d22d517e888c44e6bf49a58aba336ffdf6b306e978fd396e050150df4ea2.js?body=1:22 Uncaught ReferenceError: d3 is not defined
    at nvd3.self-f952d22d517e888c44e6bf49a58aba336ffdf6b306e978fd396e050150df4ea2.js?body=1:22
    at nvd3.self-f952d22d517e888c44e6bf49a58aba336ffdf6b306e978fd396e050150df4ea2.js?body=1:15425
(anonymous) @ nvd3.self-f952d22d517e888c44e6bf49a58aba336ffdf6b306e978fd396e050150df4ea2.js?body=1:22
(anonymous) @ nvd3.self-f952d22d517e888c44e6bf49a58aba336ffdf6b306e978fd396e050150df4ea2.js?body=1:15425
chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:3587 Uncaught TypeError: Cannot read property '0' of undefined
    at ChartType.buildScale (chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:3587)
    at ChartType.initialize (chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:3470)
    at ChartType.Chart.Type (chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:915)
    at new ChartType (chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:1150)
    at Chart.<computed> [as Radar] (chart.self-fd14d3b9af2040b3f73dce5df87d357f24b5df47af973d28fbc5d9a4b39ae8b9.js?body=1:1178)
    at 123:119

I am using a copy paste from the sample data.
Where can i get information on how to build the JSON object needed to generate the Radar graph?
Thanks,

Option for stacked bar chart

I am using this gem (chart js) for my generating radar and bar charts on pdf. It works great. However, I couldn't find the option for stacked bar chart. Are they included in the gem?

I'm looking for this chart:

image

Currently, this is the chart I have generated.

image

I tried to look for alternative such as chart-js-ror. It has the stacked bar chart option but rendering pdf causes a lot of issues, particularly label inconsistency and responsive problems. And also the pdf generated has some blurred lines. Just wonder if there's such option and sharper image for the chart in this gem. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.