Skip to content

ashrafuzzaman/chartify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chartify

The purpose of this gem is to capture data to create a chart, in an object, so that we can do the following things

  • Render javascript graph, (which can be chart library agnostic)
  • Create the chart data using ruby only (no js to render chart)
  • Export chart as image (Needed when you want to email a chart)
  • Configuration for chart colors

Note

The project is in progress. So please wait for the release.

The project is similar to chartkick. The reason I am planning to create another project is because it does not support to export charts in image.

Charts supported

  • Line chart
  • Bar chart
  • Pie chart

For generating image from the chart data we are using Gruff

Here are some sample code to generate graph object and render to web.

@chart = Chartify::Factory.build(:line) do |chart|
  chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
                {hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
                {hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
  chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
  chart.label_column = :day
end

In the web page,

<div id="chart" style="width: 900px; height: 180px;"></div>
<%= @chart.render_chart('chart') %>

To export the chart as image,

@chart.to_blob

Now you can attach the blob to email or in the PDF file.

License

This project rocks and uses MIT-LICENSE.

About

A chart api to generate image and web chart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages