API Charts

This is the official documentation of the agent_ruby Ruby agent.

API charts in the legacy agents were declared using routes.

In the new agent, you will need to use either the agent.add_chart or the collection.add_chart function, depending on if the chart is to be displayed on a record of a collection or a dashboard.

You can find the full documentation of chart customization here.

Code cheatsheet

Legacy agent
New agent

route in routes.rb

agent.add_chart collection.add_chart(...)

render ForestLiana::Model::Stat

return result_builder.value(...) return result_builder.distribution(...)

request object

context.record_id

How to migrate

Migrating should be straightforward: the only differences are that:

  • dashboard charts are now declared using the agent.add_chart function.

  • collection charts are now declared using the collection.add_chart function, and access the record id using context.record_id instead of request.query?.record_id.

  • Both types should use the resultBuilder helper to return the chart data.

  • Define a new route in routes.rb:

  • Setup an action into a controller

def mrr
    mrr = 0

    Stripe.api_key = 'sk_AABBCCDD11223344'
    Stripe::Charge.list.list({ limit: 3 }).each do |charge|
        mrr += charge.amount
    end

    stat = ForestLiana::Model::Stat.new({ value: mrr })
    render json: serialize_model(stat)
  end

Last updated