No commit activity in last 3 years
No release in over 3 years
chartjs-zoomable lets you use Chartjs graphs using helper methods in your views with zoom and pan functionality
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 3.6.2
~> 5.2.1
 Project Readme

chartjs-zoomable

Simplifies usage of Chart.js in Rails views with zoom and pan plugin!

Installation

Add this line to your application's Gemfile:

gem 'chartjs-zoomable'

And then execute:

$ bundle

Add the following to your application.js:

$ //= require chartjs/zoomable/application.js

Usage

Each chart type has a corresponding helper for your views. The helper methods take the same arguments as their Javascript counterparts. The options are optional. They allow you to make a graph zoomable:

<%= line_chart           data, options %>
<%= bar_chart            data, options %>
<%= horizontal_bar_chart data, options %>
<%= radar_chart          data, options %>
<%= polar_area_chart     data, options %>
<%= pie_chart            data, options %>
<%= doughnut_chart       data, options %>
<%= bubble_chart         data, options %>
<%= scatter_chart        data, options %>

If you don't want these helpers – perhaps they clash with other methods in your views – add this initializer to your app:

# config/initializers/chartjs.rb
Chartjs.no_conflict!

Then you can use these helpers instead:

<%= chartjs_line_chart           data, options %>
<%= chartjs_bar_chart            data, options %>
<%= chartjs_horizontal_bar_chart data, options %>
<%= chartjs_radar_chart          data, options %>
<%= chartjs_polar_area_chart     data, options %>
<%= chartjs_pie_chart            data, options %>
<%= chartjs_doughnut_chart       data, options %>
<%= chartjs_bubble_chart         data, options %>
<%= chartjs_scatter_chart        data, options %>

For example, to render a [line chart][linechart] with zoom:

data = {
  labels: ["March", "April", "May", "June", "July", "August", "September"],
  datasets: [
    {
        label: "My First dataset",
        backgroundColor: "rgba(220,220,220,0.2)",
        borderColor: "rgba(220,220,220,1)",
        data: [67, 58, 80, 81, 56, 55, 40]
    },
    {
        label: "My Second dataset",
        backgroundColor: "rgba(151,187,205,0.2)",
        borderColor: "rgba(151,187,205,1)",
        data: [28, 48, 40, 19, 86, 27, 91]
    }
  ]
}
options = {
  id: "my_first_graph",
  zoom: {
    enabled: true,
    mode: 'x',
  },
}
<%= line_chart data, options %>

Contributing

Contribution directions go here.

License

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