From 172c6fe8951092f0b18cd6a7f68c5d1adf564f3e Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 24 May 2023 12:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B0=94=E8=B1=A1=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Components.php | 56 +++++++++++++++++++++++++++- app/Services/Admin/DeviceService.php | 42 +++++++++++++++++++-- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/app/Admin/Components.php b/app/Admin/Components.php index ea688ff..21d560c 100644 --- a/app/Admin/Components.php +++ b/app/Admin/Components.php @@ -97,6 +97,7 @@ class Components extends BaseRenderer { public function chartLineBarConfig($title = '', array $x , array $y){ $yAxisData = []; $seriesData = []; + $color = []; if(!isset($y[0])){ $_y = $y; $y = [0=>$_y]; @@ -104,11 +105,13 @@ class Components extends BaseRenderer { $i = 0; $tips = '{b0}'; foreach($y as $item) { + //调色盘 + $color[] = $item['color']; //tips $tips.= '
{a'.$i.'}: {c'.$i.'}'.($item['unit'] ?? ''); //纵坐标 $yAxisData[] = [ - 'name'=>$item['name'].($item['unit'] ?? ''), + 'name'=>($item['unit'] ?? ''), 'type' =>'value', 'axisTick' => true, 'alignTicks' => true, @@ -119,7 +122,7 @@ class Components extends BaseRenderer { ] ], 'axisLabel'=> [ - 'formatter'=>'{value} '.($item['unit'] ?? '') + 'formatter'=>'{value} ' ] ]; //数据 @@ -143,6 +146,8 @@ class Components extends BaseRenderer { ]); break; case 'bar': + $_series = array_merge($_series, [ + ]); break; } $seriesData[] = $_series; @@ -150,6 +155,7 @@ class Components extends BaseRenderer { } return [ + 'color' => $color, 'title' => [ 'text' => $title, ], @@ -172,6 +178,52 @@ class Components extends BaseRenderer { 'series' => $seriesData ]; } + + /** + * 散点图 + */ + public function chartScatterConfig($title = '', array $x , array $y, array $yData = null){ + $yAxisData = []; + $seriesData = []; + $color = []; + + if($yData){ + $yAxisData = [ + 'type' =>'category', + // 'splitLine'=>[ + // 'show'=>true, + // 'lineStyle'=>[ + // 'type'=>'dashed' + // ] + // ], + 'axisTick' => [ + 'alignWithLabel'=>true + ], + 'data'=> $yData + ]; + } + + $seriesData = $y; + + return [ + 'color' => $color, + 'title' => [ + 'text' => $title, + ], + "tooltip" => [//提示 + 'trigger'=>'axis',//坐标轴触发 + 'axisPointer' => [ + 'type' => 'cross' + ], + ], + 'xAxis' => [ + 'type' => 'category', + 'data' => $x, + ], + 'yAxis' => $yAxisData, + 'series' => $seriesData + ]; + } /** * 生成饼状图config diff --git a/app/Services/Admin/DeviceService.php b/app/Services/Admin/DeviceService.php index e15f6a0..5f3a1ec 100644 --- a/app/Services/Admin/DeviceService.php +++ b/app/Services/Admin/DeviceService.php @@ -142,9 +142,45 @@ class DeviceService extends BaseService $k++; //特殊字段,特殊统计图; - switch($field){ - //点状图;-todo - //柱状图;-todo + switch($key){ + //点状图; + case 'wind_direction': + $yData = ['北风','东北风','东风','东南风','南风','西南风','西风','西北风']; + $_chartCard = amisMake()->Card()->body( + amisMake()->Chart()->config( + Components::make()->chartScatterConfig($field['name'], $xKeys, + [ + 'name'=> $field['name'], + 'type' => 'scatter', + 'symbolSize' => 15, + 'data' => array_map(function($item)use($yData){ + return $yData[$item]; + },$field['data']), + 'color' => '#91CC75', + ], $yData + ) + ) + ); + break; + //柱状图; + case 'box_noise': + case 'pm10': + case 'pm25': + case 'box_co2': + $_chartCard = amisMake()->Card()->body( + amisMake()->Chart()->config( + Components::make()->chartLineBarConfig($field['name'], $xKeys, [ + [ + 'name'=> $field['name'], + 'type' => 'bar', + 'data' => $field['data'], + 'color' => '#91CC75', + 'unit' => $field['unit'] + ] + ]) + ) + ); + break; default://折线图 $_chartCard = amisMake()->Card()->body( amisMake()->Chart()->config(