Average Last updated: 2023-09-17
The Average object is a valuable component for calculating the mean or average value of a set of numerical data points. It provides a straightforward and efficient way to determine the central tendency of a dataset.
By utilizing the Average object, you can input a series of numerical values and compute their average. This object performs the necessary calculations, summing up the values and dividing them by the total count, providing the mean value.
The Average object is widely used in statistical analysis, data processing, and various domains where understanding the average value is essential. It allows you to gain insights into the overall trend or typical value within a dataset.
The object is particularly useful when dealing with large datasets or when you need to summarize numerical data in a concise manner. It simplifies the process of obtaining the average value, saving time and effort in manual calculations.
In summary, the Average object provides a convenient way to calculate the mean or average value of a set of numerical data points. It is a valuable tool for statistical analysis and data processing, enabling you to gain insights into the central tendency of a dataset.
Example:
An object can be created using the command
php artisan dash:average Invoice
#[app/Dash/Metrics/Averages/Invoice.php]
#Invoice Average generated
# or write --module flag to Create in specific module
php artisan dash:average Invoice --module=Invoices
output:-
<?php
namespace App\Dash\Metrics\Averages;
use Dash\Extras\Metrics\Average;
class Invoice extends Average{
/**
* calculate method is short to calc to using in value
* for more information about this visit https://phpdash.com/docs/1.x/Metrics#Value
* @return $this->average method
*
*/
public function calc(){
return $this->average(Invoice::class,'total')
// ->bgClass('bg-success') change bar background color optional // bg-success , bg-info , bg-warning , bg-danger
// ->at('created_at') // optional
// ->column(3) // optional
// ->height('10') change bar height optional // 0 to 100
// ->href(dash('resource/YourResourceOr Other Links'))
// ->icon('<i class="fa fa-users"></i>') icon by fontawesome or other | optional
// ->title('Your Title') // optional
// ->subTitle('Your subTitle') optional
// ->textBody('Text In Body') // optional
// ->prefix('<i class="fa fa-user"></i> ') add prefix before number or icon
// ->suffix('Your suffix') // optional add suffix after number
;
}
}
How to Use ?
You Can Use In Vertex In Resource or Dashboard Class with →render()
method like this :-
<?php
namespace App\Dash\Dashboard;
use App\Dash\Metrics\Averages\Invoice;
use Dash\Resource;
class Help extends Resource {
/**
* add your card here by Card , HTML Class
* or by view instnance render blade file
* @return array
*/
public static function cards() {
return [
(new Invoice)->render(),
// or if you need to reformat value
(new Users)->formatValue(function($value){
return number_format($value,2);
})->render(),
];
}
}