Skip to content

Rendering Report Metrics

Daniel Vandersluis edited this page Apr 5, 2014 · 2 revisions

Note: The code demonstrated on this page is available as part of the compendium_demo project, which you can clone and play with yourself. This sample application gives a simple report outlining spending over a given period.

A metric is a piece of data extracted from your report (for instance, the total spending for the report period). Metrics are derived from queries:

metric :total, through: :spending do |results|
  results.map{ |r| r[:amount] }.sum
end

To render a metric, just call render on it:

Code Output
@report.metrics[:total].render(self, description: 'USD')
image

####Notes

  • The first parameter given to render is the current view context, which is needed to call other view methods.
  • In order to use the default CSS, ensure that compendium/report.css is loaded
  • By default, the metric label is I18n.translate('<report_name>.<metric_name>'). If you do not with to use I18n, the label can be provided in the options given to render (ie. render(self, label: 'My Label'))
Clone this wiki locally