colors = [$color->green(), $color->red(), $color->yellow(), $color->orange1(), $color->dark90(), $color->dark70(), $color->custom()]; $this->contentWidth(3, 9); $this->title('销售排行'); //$this->chartPullRight = false; //$this->subTitle('Last 30 days'); $this->height = 280; $this->chartHeight = 250; // 设置图表颜色 $this->chartColors($this->colors); } /** * 渲染模板 * * @return string */ public function render() { $this->fill(); return parent::render(); } /** * 写入数据. * * @return void */ public function fill() { $warehouse = Order::query() ->with('agentProduct') ->select('*') ->addSelect(DB::raw('count(id) as count_id')) ->where([ //'status' => OrderStatus::SUCCESS, 'agent_id' => Admin::user()->id, ]) ->orderByDesc('count_id') ->groupBy('agent_product_id') ->limit(5) ->get(); //$warehouse = []; $data = $categories = []; foreach ($warehouse as $v) { array_push($this->labels, $v->title); array_push($data, $v->count_id); $categories[] = [$v->title]; } $this->withChart($data, $categories); //$this->chartLabels($this->labels); $count = Order::query() ->where([ //'status' => OrderStatus::SUCCESS, 'agent_id' => Admin::user()->id, ]) ->count(); //$count = 0; if ($count > 0) { array_unshift($data, $count); array_unshift($this->labels, '总销售量'); $color = Admin::color(); array_unshift($this->colors, $color->primary()); } $this->withContent($data); } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart($data, $categories) { return $this->chart([ 'series' => [[ 'name' => '出库数量', 'data' => $data ]], 'chart' => [ //'width' => '180%', 'type' => 'bar', 'events' => [ ], 'toolbar' => ['show' => false], ], 'colors' => $this->colors, 'plotOptions' => [ 'bar' => [ //'columnWidth' => '45%', 'distributed' => true, ] ], 'dataLabels' => [ 'enabled' => false ], 'legend' => [ 'show' => false ], 'xaxis' => [ 'categories' => $categories , 'labels' => [ 'show' => false, 'style' => [ 'colors' => $this->colors, 'fontSize' => '12px' ] ], ], 'yaxis' => [ 'show' => false ], 'tooltip' => [ 'x' => ['show' => true], ], ]); } /** * 设置卡片头部内容. * * @param mixed $desktop * @param mixed $mobile * * @return $this */ protected function withContent($data) { $content = ''; foreach ($data as $k => $v) { $content .= '