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

Separate large numbers in the table with commas #54

Open
billy-whizz opened this issue Oct 5, 2019 · 8 comments
Open

Separate large numbers in the table with commas #54

billy-whizz opened this issue Oct 5, 2019 · 8 comments

Comments

@billy-whizz
Copy link

Hi, is there a way to display large figures in the table with a comma to make them easy to understand at first glace? I know in the views I could have used the number_with_delimiter method, but am not sure how that works with the charts.

@nsoseka
Copy link

nsoseka commented Oct 5, 2019

i think to make things easy for you you will have to write a custom data searching method and format the numbers the way you want before passing it onto the gem for rendering. If you need assistance on how to go about that let me know

@billy-whizz
Copy link
Author

Thank you @nsoseka. How would I go about that?

@nsoseka
Copy link

nsoseka commented Oct 5, 2019

So you check out the docs on how to setup custom data methods.
checkout this link https://www.reportskit.co/subcategories/data_methods
Then you can format your data as you normally would in rails or ruby, in your custom method.

@billy-whizz
Copy link
Author

billy-whizz commented Oct 6, 2019

Thanks for pointing that out. In app/services/my_data_methods.rb I have used this method:
def self.delimit_figures
ActionController::Base.helpers.number_to_currency(authors.salary, precision: 0)
end

Not much success though

@nsoseka
Copy link

nsoseka commented Oct 7, 2019

okay require the number_to_currency_helper

require "active_support/number_helper/number_converter"

  module Helpers
    extend ActiveSupport::NumberHelper
  end

Define a custom number_to_currency method

  def number_to_currency(amount)
    Helpers.number_to_currency(amount)
  end

This method you can then call within your custom data method. If you need more support you can post your entire data method if you will, so that i can show you how to navigate using the method in it

@billy-whizz
Copy link
Author

Thanks a lot!

After requiring the helper, here is the method in my_data_methods.rb:

def self.delimit_figures
Author.number_to_currency(salary)
end
Any ideas are welcome.,thanks

@nsoseka
Copy link

nsoseka commented Oct 8, 2019

This method returns the value of Author.number_to_currency(salary) and not a JSON object. So the view of reports_kit can't render it.
Because you have a custom data method, you need to do the querying yourself and then format the data before return it as JSON. So if I had an idea of the type of data you were trying to retrieve then i could be of more help.

@billy-whizz
Copy link
Author

billy-whizz commented Oct 26, 2019

Hi, so I recently returned to this but yet to get a solution. I think am yet to get the hang of it.
My authors table has a salary field, with data type as decimal. In the views, I have a chart which shows a summary of authors' salaries by country. I would like the totals/figures to be well formatted for easy understanding.
My my_data_methods.rb looks like this now:

class MyDataMethods

 require "active_support/number_helper/number_converter"

  module Helpers
    extend ActiveSupport::NumberHelper
  end

  def number_to_currency(amount)
    Helpers.number_to_currency(amount)
  end

   def self.delimit_figures(properties)
    salaries = Author.salary 
    salaries.number_to_currency 
  end

end

My salary_chart.yml looks like this:

--- 
data_method: MyDataMethods.delimit_figures
dimensions: 
  - country
  - genre
filters: 
  - country
  - genre
format: table
measure: 
  aggregation: total_salary
  key: author
  name: "Total Salaries by Country"
report_options: 
  aggregations: 
    - 
      from: columns
      label: Total
      operator: sum
    - 
      from: rows
      label: Total
      operator: sum

In the view:

<%= render_report 'salary_chart' do |report| %>
  <%= report.form do |f| %>
   <%= f.multi_autocomplete :country, placeholder: 'Genre...' %>
    <%= f.multi_autocomplete :genre, placeholder: 'County...' %>
  <% end %>

I think the only task is in the data method part. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants