海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.0 KiB

4 years ago
  1. <?php
  2. namespace App\AdminAgent\Metrics\Examples;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Widgets\Metrics\Bar;
  5. use Illuminate\Http\Request;
  6. class FinanceStatistics extends Bar
  7. {
  8. /**
  9. * 初始化卡片内容
  10. */
  11. protected function init()
  12. {
  13. parent::init();
  14. $color = Admin::color();
  15. // 卡片内容宽度
  16. $this->contentWidth(0, 12);
  17. // 标题
  18. //$this->title('财务统计');
  19. $this->chartHeight = 500;
  20. // 设置下拉选项
  21. $this->dropdown([
  22. '7' => '日',
  23. '30' => '月',
  24. '365' => '年',
  25. ]);
  26. // 设置图表颜色
  27. $this->chartColors([
  28. $color->green(),
  29. ]);
  30. }
  31. /**
  32. * 处理请求
  33. *
  34. * @param Request $request
  35. *
  36. * @return mixed|void
  37. */
  38. public function handle(Request $request)
  39. {
  40. switch ($request->get('option')) {
  41. case '7':
  42. default:
  43. // 图表数据
  44. $this->withChart(
  45. [75, 125, 225, 175, 125, 75, 25]
  46. );
  47. }
  48. }
  49. /**
  50. * 设置图表数据.
  51. *
  52. * @param array $data
  53. *
  54. * @return $this
  55. */
  56. public function withChart(array $data)
  57. {
  58. return $this->chart([
  59. 'series' => [[
  60. 'name' => '金额',
  61. 'data' => $data
  62. ]],
  63. 'chart' => [
  64. //'width' => '180%',
  65. 'type' => 'bar',
  66. 'events' => [
  67. ],
  68. 'toolbar' => ['show' => false],
  69. ],
  70. 'colors' => $this->colors,
  71. 'plotOptions' => [
  72. 'bar' => [
  73. //'columnWidth' => '45%',
  74. 'distributed' => true,
  75. ]
  76. ],
  77. 'dataLabels' => [
  78. 'enabled' => false
  79. ],
  80. 'legend' => [
  81. 'show' => false
  82. ],
  83. 'xaxis' => [
  84. 'categories' =>
  85. [75, 125, 225, 175, 125, 75, 25]
  86. ,
  87. 'labels' => [
  88. 'show' => true,
  89. 'style' => [
  90. 'colors' => $this->colors,
  91. 'fontSize' => '12px'
  92. ]
  93. ],
  94. ],
  95. 'yaxis' => [
  96. 'show' => true
  97. ],
  98. 'tooltip' => [
  99. 'x' => ['show' => true],
  100. ],
  101. ]);
  102. }
  103. }