Value Last updated: 2023-09-30

numerical statistics involve analyzing and interpreting data using Value objects. These objects encapsulate numeric values and provide essential functionalities for statistical calculations. They enable operations like summation, averaging, and determining minimum and maximum values. Value objects ensure consistency and accuracy in handling numerical data and can be integrated with other statistical tools for comprehensive analysis and visualization.

Example :

In summary, the system allows for the customization of statistics based on various time intervals, empowering users to gain insights into data patterns and trends within specific days, months, years, weeks, or any other desired timeframe.

An object can be created using the command

php artisan dash:value Users 
#[app/Dash/Metrics/Values/Users.php]
#Users Value generated
# or write --module flag to Create in specific module
php artisan dash:value Users --module=Users


output :- 

<?php
namespace App\Dash\Metrics\Values;
use Dash\Extras\Metrics\Value;

class Users extends Value{
 
    /**
     * 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->sum or count method
     *
     */
      public function calc(){
        return
        $this->count(YourModel::class) // or sum // $this->sum(YourModel::class,'id') | id column is optional
       // ->at('created_at') // optional
       // ->column(3) // optional
       // ->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
       ;
    }

     /**
     * ranges
     * enable dropdown select to set range to count or sum data you can add more by days like 730
     * @return array
     */
    public function ranges(){
        return [
            'all'=>'All',
            'today'=>'Today',
            'yesterday'=>'Yesterday',
            '3'=>'last 3 days',
            '4'=>'last 4 days',
            'week'=>'Week',
            'month'=>'month',
            'year'=>'year',
            '730'=>'2 years',
        ];
    }

}

ranges()  

In addition to the aforementioned features, the Value object also includes a function called "ranges." This method allows users to specify default values for aggregation based on the number of days, weeks, months, years, or any other desired duration.

 

public function ranges(){
        return [
            'all'=>'All',
            'today'=>'Today',
            'yesterday'=>'Yesterday',
            '3'=>'last 3 days',
            '4'=>'last 4 days',
            'week'=>'Week',
            'month'=>'month',
            'year'=>'year',
            '730'=>'2 years',
            // you can add more days
        ];
    }

 

you can use sum method to sum pricing or sum any numbers

 
   public function calc(){
        return $this->sum(Invoice::class,'total');
    }

 

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\Values\Users;

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 Users)->render(),
                 // or if you need to reformat value 
                 (new Users)->formatValue(function($value){
             					   return number_format($value,2);
            			    })->render(),
		];
	}

}