shipping = $shipping; parent::__construct($title = null, $icon = null); } public function init() { parent::init(); // TODO: Change the autogenerated stub $color = Admin::color(); $colors = [$color->primary(), $color->alpha('blue2', 0.5)]; //$this->title('配送数据'); $this->height = 152; $this->chartLabels($this->labels); // 设置图表颜色 $this->chartColors($colors); } /** * 渲染模板 * * @return string */ public function render() { $this->fill(); return parent::render(); // TODO: Change the autogenerated stub } /** * 写入数据. * * @return void */ public function fill() { $total = array_sum($this->shipping); $s3 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[0] / $total) * 100) . '%':'0%'; $s4 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[1] / $total) * 100) . '%':'0%'; // 图表数据 $this->withChart($this->shipping); $this->withContent($this->shipping[0], $this->shipping[1], $s3, $s4); } /** * 设置图表数据. * * @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($s1, $s2, $s3, $s4) { $blue = Admin::color()->alpha('blue2', 0.5); $style = 'margin-bottom: 8px'; $labelWidth = 120; return $this->content( <<
{$this->labels[0]}
{$s1}
{$this->labels[1]}
{$s2}
{$this->labels[2]}
{$s3}
{$this->labels[3]}
{$s4}
HTML ); } }