Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Association in charts and pie chart theme #34

Closed
mostafahussein opened this issue Sep 19, 2013 · 5 comments
Closed

Association in charts and pie chart theme #34

mostafahussein opened this issue Sep 19, 2013 · 5 comments

Comments

@mostafahussein
Copy link

First thanks alot for this gem i have been trying for more than a month to create a dynamic gem but i always fail, but its easier with your gem thanks alot <3 .

Second I have Ticket model belongs_to employee_department and belongs_to state , i would like to show on pie chart the count of states (in state model i have :name attribute ) for each employee_department ( :name attribute ).

Third I used pie chart with one model it looks different from the one you have in the example ( your pie chart example shows with percentage and small squares ), how you change its theme ?

Note: I have <%= javascript_include_tag "/assets/highcharts.js", "chartkick" %>
thanks again for this gem 👍

@ankane
Copy link
Owner

ankane commented Sep 20, 2013

This should work if names are unique.

EmployeeDepartment.joins(:states).group("employee_departments.name").count

Make sure

class EmployeeDepartment
  has_many :tickets
  has_many :states, through: :tickets
end

An alternative approach is:

EmployeeDepartment.all.map{|dept| dept.states.count }

The examples use Google Charts, which is why the theme is different.

@mostafahussein
Copy link
Author

Tickets.rb
belongs_to :employee_department
belongs_to :state

Employee_department.rb
has_many :tickets

State.rb
has_many :tickets

i will add has_many states through tickets into my employee_department.rb , is there anything else need to be modified ?

@ankane
Copy link
Owner

ankane commented Sep 20, 2013

No, that should be it. Try out the two examples above to see if they work.

@mostafahussein
Copy link
Author

I tried one of them ,the pie chart is showing the number of tickets for each department

@ankane
Copy link
Owner

ankane commented Sep 20, 2013

Sounds like you want the number of distinct states. Try the second solution.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants