DataLabel2.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 DataLabel2 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 $series, array $categories)
  43. {
  44. $this->chart([
  45. 'chart' => [
  46. 'type' => 'area',
  47. 'toolbar' => [
  48. 'show' => false,
  49. ],
  50. ],
  51. 'series' => $series,
  52. 'dataLabels' => [
  53. 'enabled' => true
  54. ],
  55. 'xaxis' => [
  56. 'type' => 'number',
  57. 'categories' => $categories,
  58. 'labels' => [
  59. 'show' => true,
  60. ],
  61. 'axisBorder' => [
  62. 'show' => true,
  63. ],
  64. ],
  65. 'tooltip' => [
  66. 'x' => [
  67. 'show' => true
  68. ]
  69. ],
  70. ]);
  71. }
  72. }