Skip to content
Daniel Vandersluis edited this page Apr 5, 2014 · 1 revision

Sometimes you will want to render a chart which loads its data remotely (perhaps in order to create a chart on demand, or only show queries that your user wants to see). Compendium lets you do this in a couple ways:

  • By rendering a chart for a query which has not yet been run. This can be a query retrieved from a report class, or a query not yet run from a report instance.

    MyReport.queries[:my_query].render_chart(self, :pie) do
      # configure your chart
    end
  • Passing remote: true to render_chart, regardless of if the query has been run yet or not.

    report.query.render_chart(self, :pie, remote: true) do
      # ...
    end

With either method, Compendium will set up a remote load automatically, using the JSON URL for the given query. Furthermore, if your controller has CSRF protection enabled (as it is by default), Compendium will automatically add the required authentication token parameter to the request.

Other parameters can be specified by adding the :params option when calling render_chart:

report.query.render_chart(self, :pie, remote: true, params: { starting_on: Date.today - 1.month }) do
  # ...
end

To keep in line with the conventions Compendium uses, any params specified will be put into a :report hash which the ReportsController expects to receive:

Started POST "/reports/my_report/my_query.json" for 127.0.0.1 at 2014-04-05 18:31:51 -0400
Processing by Compendium::ReportsController#run as JSON
  Parameters: {"report"=>{"starting_on"=>"2014-03-05"}, "authenticity_token"=>"8bVdXhjKSKiwVI3JEM67XkrfMoMFiGCYYVJXy/SHb7s=", "report_name"=>"my_report", "query"=>"my_query"}
Clone this wiki locally