GoodsActivityReport = new GoodsActivityReport(); $this->option = $this->id = 7; // 分页的时候不重复查询数据 $currentPage = request()->input('page', 1); if($currentPage == 1){ $data = $this->GoodsActivityReport->getMarketData(); $market = MarketModel::getMarketArray(); if(!empty($data) && is_array($data)){ $total = 0; foreach($data as $key => $value){ $this->data[] = (int)$value['total']; $this->labels[] = $market[$value['market_id']]??'未知'; $this->colors[] = $this->color[$key]; $total += $value['total']; } $this->total['number_total'] = $total; } } parent::__construct(); } protected function init() { parent::init(); // 设置标题 $this->title('各市场销售量(单)'); $this->subTitle('各市场销售量的占比图'); $this->chartHeight(170); // 设置下拉菜单 // $this->dropdown([]); $this->chartLabels($this->labels); // 设置图表颜色 $this->chartColors($this->colors); } /** * 处理请求 * 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 * * @param Request $request * @return mixed|void */ public function handle(Request $request) { // 数据查询逻辑 $data = $this->data; $this->withContent($data); $this->withChart($data); } /** * 这里返回需要异步传递到 handler 方法的参数 * * @return array */ public function parameters(): array { return [ 'id' => $this->id, 'option' => $this->option, ]; } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * 渲染卡片内容. * * @return string */ public function withContent($data = []) { $div = ''; $style = 'margin-bottom: 8px'; if(!empty($data) && is_array($data)){ foreach($data as $key => $value){ $div .= '