BarChartCard.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Dcat\Admin\Widgets\Metrics;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Support\Helper;
  5. use Illuminate\Contracts\Support\Renderable;
  6. class BarChartCard extends RadialBarChartCard
  7. {
  8. /**
  9. * 内容宽度.
  10. *
  11. * @var array
  12. */
  13. protected $contentWidth = [4, 8];
  14. /**
  15. * @var int
  16. */
  17. protected $chartHeight = 200;
  18. /**
  19. * @var int
  20. */
  21. protected $chartMarginBottom = 0;
  22. /**
  23. * @var bool
  24. */
  25. protected $chartPullRight = true;
  26. /**
  27. * 图表默认配置.
  28. *
  29. * @return array
  30. */
  31. protected function defaultChartOptions()
  32. {
  33. $color = Admin::color();
  34. $colors = [
  35. $color->primary()
  36. ];
  37. return [
  38. 'chart' => [
  39. 'type' => 'bar',
  40. 'height' => 200,
  41. 'sparkline' => ['enabled' => true],
  42. 'toolbar' => ['show' => false],
  43. ],
  44. 'states' => [
  45. 'hover' => [
  46. 'filter' => 'none',
  47. ],
  48. ],
  49. 'colors' => $colors,
  50. 'series' => [
  51. [
  52. 'name' => 'Title',
  53. 'data' => [75, 125, 225, 175, 125, 75, 25],
  54. ],
  55. ],
  56. 'grid' => [
  57. 'show' => false,
  58. 'padding' => [
  59. 'left' => 0,
  60. 'right' => 0,
  61. ],
  62. ],
  63. 'plotOptions' => [
  64. 'bar' => [
  65. 'columnWidth' => '44%',
  66. 'distributed' => true,
  67. //'endingShape' => 'rounded',
  68. ],
  69. ],
  70. 'tooltip' => [
  71. 'x' => ['show' => false],
  72. ],
  73. 'xaxis' => [
  74. 'type' => 'numeric',
  75. ],
  76. ];
  77. }
  78. /**
  79. * 设置柱间距.
  80. *
  81. * @param string $value
  82. *
  83. * @return $this
  84. */
  85. public function chartBarColumnWidth($value)
  86. {
  87. return $this->chartOption('plotOptions.bar.columnWidth', $value);
  88. }
  89. }