fix: special trend should show most recent data, order desc then reverse for chart display
This commit is contained in:
@@ -370,12 +370,15 @@ class History extends Model
|
|||||||
*/
|
*/
|
||||||
public function getSpecialTrend($periods = 30)
|
public function getSpecialTrend($periods = 30)
|
||||||
{
|
{
|
||||||
$history = $this->field('expect,num7')->order('openTime', 'asc')->limit($periods)->select();
|
|
||||||
if (empty($history)) return ['expects' => [], 'specials' => [], 'colors' => []];
|
|
||||||
|
|
||||||
$num_model = new Num();
|
$num_model = new Num();
|
||||||
$colorMap = $num_model->column('color', 'num');
|
$colorMap = $num_model->column('color', 'num');
|
||||||
|
|
||||||
|
// 先取最近 $periods 条数据
|
||||||
|
$history = $this->field('expect,num7,openTime')->order('openTime', 'desc')->limit($periods)->select();
|
||||||
|
if (empty($history)) return ['expects' => [], 'specials' => [], 'colors' => []];
|
||||||
|
|
||||||
|
// 反转,使数据从左到右为从远到近
|
||||||
|
$history = array_reverse($history);
|
||||||
$expects = []; $specials = []; $colors = [];
|
$expects = []; $specials = []; $colors = [];
|
||||||
foreach ($history as $row) {
|
foreach ($history as $row) {
|
||||||
$expects[] = (string)$row['expect'];
|
$expects[] = (string)$row['expect'];
|
||||||
|
|||||||
Reference in New Issue
Block a user