Value Charts display a single numerical value.
Copy use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Context \ AgentCustomizationContext ;
use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Decorators \ Chart \ ResultBuilder ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ Aggregation ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ ConditionTree \ ConditionTreeFactory ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ ConditionTree \ Operators ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ Filters \ Filter ;
$forestAgent -> addChart (
'monthlyRecuringRevenue' ,
function ( AgentCustomizationContext $context , ResultBuilder $resultBuilder) {
$aggregation = new Aggregation ( 'Sum' , 'amount' );
$filter = new Filter (
ConditionTreeFactory :: fromArray ( [ 'field' => 'status' , 'operator' => Operators :: EQUAL , 'value' => paid] )
);
$value = $context -> getDatasource () -> getCollection ( 'Payment' ) -> aggregate ( $filter , $aggregation ) ;
return $resultBuilder -> value ( $value )
}
) ;
Copy use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ CollectionCustomizer ;
use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Decorators \ Chart \ CollectionChartContext ;
use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Decorators \ Chart \ ResultBuilder ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ Aggregation ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ ConditionTree \ ConditionTreeFactory ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ ConditionTree \ Operators ;
use ForestAdmin \ AgentPHP \ DatasourceToolkit \ Components \ Query \ Filters \ Filter ;
$forestAgent -> customizeCollection ( 'Customer' , fn ( CollectionCustomizer $builder) => $builder -> addChart (
'monthlyRecuringRevenue' ,
function ( CollectionChartContext $context , ResultBuilder $resultBuilder) {
$aggregation = new Aggregation ( 'Count' , 'id' );
$filter = new Filter (
ConditionTreeFactory :: fromArray (
[
'aggregator' => 'And' ,
'conditions' => [
[ 'field' => 'status' , 'operator' => Operators :: EQUAL , 'value' => 'paid' ]
[ 'field' => 'customer:id' , 'operator' => Operators :: EQUAL , 'value' => $context -> getRecordId () ]
]
]
)
);
$value = $context -> getDatasource () -> getCollection ( 'Payment' ) -> aggregate ( $filter , $aggregation ) ;
return $resultBuilder -> value ( $value )
}
) ;
Copy use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Context \ AgentCustomizationContext ;
use ForestAdmin \ AgentPHP \ DatasourceCustomizer \ Decorators \ Chart \ ResultBuilder ;
$forestAgent -> addChart (
'appointments' ,
function ( AgentCustomizationContext $context , ResultBuilder $resultBuilder) {
return $resultBuilder -> value ( 784 , 760 )
}
) ;