链街Dcat后台
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.

114 lines
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Chart\Bar;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Widgets\ApexCharts\Chart;
  5. use Dcat\Admin\Widgets\Metrics\Bar;
  6. class OrderBar extends Chart
  7. {
  8. protected $_data;
  9. public function __construct($data=[])
  10. {
  11. parent::__construct($containerSelector=null, $options=[]);
  12. dump($data);
  13. $this->_data = $data;
  14. $this->setUpOptions();
  15. }
  16. /**
  17. * 初始化图表配置
  18. */
  19. protected function setUpOptions()
  20. {
  21. $color = Admin::color();
  22. $colors = [$color->primary(), $color->primaryDarker()];
  23. $this->options([
  24. 'colors' => $colors,
  25. 'chart' => [
  26. 'type' => 'bar',
  27. 'height' => 430,
  28. ],
  29. 'plotOptions' => [
  30. 'bar' => [
  31. 'horizontal' => false,
  32. 'dataLabels' => [
  33. 'position' => 'top',
  34. ],
  35. ]
  36. ],
  37. 'dataLabels' => [
  38. 'enabled' => true,
  39. 'offsetX' => -6,
  40. 'style' => [
  41. 'fontSize' => '12px',
  42. 'colors' => ['#fff']
  43. ]
  44. ],
  45. 'stroke' => [
  46. 'show' => true,
  47. 'width' => 1,
  48. 'colors' => ['#fff']
  49. ],
  50. 'xaxis' => [
  51. 'categories' => [],
  52. ],
  53. ]);
  54. }
  55. /**
  56. * 处理图表数据
  57. */
  58. protected function buildData()
  59. {
  60. $orderType = request()->input('order_type')??'amount';
  61. // 执行你的数据查询逻辑
  62. $data = [
  63. [
  64. 'name'=>'订单金额',
  65. 'data' =>$orderType=='num'? $this->_data['num']:$this->_data['amount']
  66. ],
  67. ];
  68. $categories = $this->_data['time'];
  69. $this->withData($data);
  70. $this->withCategories($categories);
  71. }
  72. /**
  73. * 设置图表数据
  74. *
  75. * @param array $data
  76. *
  77. * @return $this
  78. */
  79. public function withData(array $data)
  80. {
  81. return $this->option('series', $data);
  82. }
  83. /**
  84. * 设置图表类别.
  85. *
  86. * @param array $data
  87. *
  88. * @return $this
  89. */
  90. public function withCategories(array $data)
  91. {
  92. return $this->option('xaxis.categories', $data);
  93. }
  94. /**
  95. * 渲染图表
  96. *
  97. * @return string
  98. */
  99. public function render()
  100. {
  101. $this->buildData();
  102. return parent::render();
  103. }
  104. }