JobDuiChart.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace UCore\DcatAdmin\Metrics\Sys;
  3. use App\Module\Statistics\Base;
  4. use Dcat\Admin\Widgets\Metrics\Line;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 队列运行情况
  8. * apex-charts
  9. */
  10. class JobDuiChart extends Line
  11. {
  12. /**
  13. * 初始化卡片内容
  14. *
  15. * @return void
  16. */
  17. protected function init()
  18. {
  19. parent::init();
  20. $this->title('任务堆积');
  21. $this->height(330);
  22. $this->chartHeight(320);
  23. }
  24. /**
  25. * 处理请求
  26. *
  27. * @param Request $request
  28. *
  29. * @return mixed|void
  30. */
  31. public function handle(Request $request)
  32. {
  33. $list = Base::getList('job', 'wait',20);
  34. $datas =[];
  35. $xd = [];
  36. foreach ($list as $value){
  37. array_unshift($datas, $value->number);
  38. array_unshift($xd, $value->pvar);
  39. }
  40. // 图表数据
  41. $this->withChart($datas,$xd);
  42. }
  43. /**
  44. * 设置图表数据.
  45. *
  46. * @param array $data
  47. *
  48. * @return $this
  49. */
  50. public function withChart(array $data, array $categories)
  51. {
  52. $this->chart([
  53. 'chart' => [
  54. 'type' => 'area',
  55. 'toolbar' => [
  56. 'show' => false,
  57. ],
  58. ],
  59. 'series' => [
  60. [
  61. 'name' => $this->title,
  62. 'data' => $data,
  63. ],
  64. ],
  65. 'dataLabels' => [
  66. 'enabled' => true
  67. ],
  68. 'xaxis' => [
  69. 'type' => 'number',
  70. 'categories' => $categories,
  71. 'labels' => [
  72. 'show' => true,
  73. ],
  74. 'axisBorder' => [
  75. 'show' => true,
  76. ],
  77. ],
  78. 'tooltip' => [
  79. 'x' => [
  80. 'show' => true
  81. ]
  82. ],
  83. ]);
  84. }
  85. }