NewDevices.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Admin\Metrics\Examples;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Widgets\Metrics\Donut;
  5. class NewDevices extends Donut
  6. {
  7. protected $labels = ['Desktop', 'Mobile'];
  8. /**
  9. * 初始化卡片内容
  10. */
  11. protected function init()
  12. {
  13. parent::init();
  14. $color = Admin::color();
  15. $colors = [$color->primary(), $color->alpha('blue2', 0.5)];
  16. $this->title('New Devices');
  17. //$this->subTitle('Last 30 days');
  18. $this->chartLabels($this->labels);
  19. // 设置图表颜色
  20. // $this->chartColors($colors);
  21. }
  22. /**
  23. * 渲染模板
  24. *
  25. * @return string
  26. */
  27. public function render()
  28. {
  29. $this->fill();
  30. return parent::render();
  31. }
  32. /**
  33. * 写入数据.
  34. *
  35. * @return void
  36. */
  37. public function fill()
  38. {
  39. $this->withContent(44.9, 28.6);
  40. // 图表数据
  41. //$this->withChart([44.9, 28.6]);
  42. }
  43. /**
  44. * 设置图表数据.
  45. *
  46. * @param array $data
  47. *
  48. * @return $this
  49. */
  50. public function withChart(array $data)
  51. {
  52. return $this->chart([
  53. 'series' => $data
  54. ]);
  55. }
  56. /**
  57. * 设置卡片头部内容.
  58. *
  59. * @param mixed $desktop
  60. * @param mixed $mobile
  61. *
  62. * @return $this
  63. */
  64. protected function withContent($desktop, $mobile)
  65. {
  66. $blue = Admin::color()->alpha('blue2', 0.5);
  67. $style = 'margin-bottom: 8px';
  68. $labelWidth = 120;
  69. return $this->content(
  70. <<<HTML
  71. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  72. <h2 class="ml-1 font-lg-1">1000</h2>
  73. </div>
  74. HTML
  75. );
  76. }
  77. }