primary(), $color->alpha('blue2', 0.5)]; $this->title('用户性别');; $this->chartLabels($this->labels); // 设置图表颜色 $this->chartColors($colors); } /** * 渲染模板 * * @return string */ public function render() { $this->fill(); return parent::render(); } /** * 写入数据. * * @return void */ public function fill() { $gender = User::query()->where('agent_id', Admin::user()->id)->pluck('gender'); $man = $woman = $unkonw = 0; foreach ($gender as $v) { if ($v == 1) { $man++; } elseif ($v == 2) { $woman++; } else { $unkonw++; } } $this->withContent($man, $woman, $unkonw); // 图表数据 $this->withChart([$man,$woman, $unkonw]); } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data ]); } /** * 设置卡片头部内容. * * @param mixed $desktop * @param mixed $mobile * * @return $this */ protected function withContent($desktop, $mobile, $unkonw) { $blue = Admin::color()->alpha('blue2', 0.5); $yellow = Admin::color()->yellow(); $style = 'margin-bottom: 8px'; $labelWidth = 120; return $this->content( <<