DataLabel.php 2.1 KB

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