Value Charts display a single numerical value.
Copy include ForestAdminDatasourceToolkit :: Components :: Query
include ForestAdminDatasourceToolkit :: Components :: Query :: ConditionTree
@create_agent . add_chart( 'monthlyRecuringRevenue' ) do | context , result_builder |
aggregation = Aggregation . new (operation: 'Sum' , field: 'amount' )
filter = Filter . new (condition_tree: Nodes :: ConditionTreeLeaf . new ( 'status' , Operators :: EQUAL , 'paid' ))
result = context . datasource . get_collection( 'payment' ) . aggregate(filter , aggregation)
result_builder . value(result[ 0 ][ 'value' ])
end
Copy include ForestAdminDatasourceToolkit :: Components :: Query
include ForestAdminDatasourceToolkit :: Components :: Query :: ConditionTree
@create_agent . customize_collection( 'customer' ) do | collection |
collection . add_chart( 'monthlyRecuringRevenue' ) do | context , result_builder |
aggregation = Aggregation . new (operation: 'Count' , field: 'id' )
filter = Filter . new (
condition_tree: Nodes :: ConditionTreeBranch . new (
'And' ,
[
Nodes :: ConditionTreeLeaf . new ( 'status' , Operators :: EQUAL , 'paid' ) ,
Nodes :: ConditionTreeLeaf . new ( 'customer:id' , Operators :: EQUAL , context . get_record_id)
]
)
)
result = context . datasource . get_collection( 'payment' ) . aggregate(filter , aggregation)
result_builder . value(result[ 0 ][ 'value' ])
end
end
Copy @create_agent . add_chart( 'appointments' ) do | _context , result_builder |
result_builder . value( 784 , 760 )
end