-3

I have to models. Employee and locations . the association between them is location has many employees. and employee belongs to location. i want to draw a pie chart between this 2 models. means i want to show all locations and employees count of that location in pie chart. how can i do that?

i was trying to implement this using the Chartkick gem.

but do not know how to draw the graph between them.

John
  • 1,273
  • 3
  • 27
  • 61

2 Answers2

0

Try gruff or rchar both should work in your case.

https://github.com/topfunky/gruff

https://github.com/amardaxini/rchart

Shravan40
  • 8,922
  • 6
  • 28
  • 48
0

In order to have piechart by using Chartkick gem we can use the method

pie_chart *argument

*argument is nothing but a hash with count of each key values

in your case you can do something like this

 pie_chart Location.includes(:employees).collect{|loc| {"#{loc.name}".to_sym => loc.employees.size}}.reduce Hash.new, :merge

it will return a hash with keys like "location name" and values to respective keys will be the employees count

Dias
  • 862
  • 8
  • 17