setUpOptions(); } //初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。 protected function setUpOptions() { $this->options([ "chart"=>[ "height"=>350, //高度 "type"=>"bar", //chart 类型 ], ]); $data = [[ "name" => "报道率", "data" => [], "tooltip" => [ [ "name" => "已报到男生", "data" => [], "color" => '#ff6b6b' ], [ "name" => "录入男生", "data" => [], "color"=>"#a21919" ] ], ]]; $label = []; // 执行你的数据查询逻辑 //取出当前年份 $config = Config::query()->where([ "unique_identification" => "annual_session" ])->first(); //二级学院 $list = SecondaryCollege::query()->where([ "status" => SecondaryCollege::STATUS_YES ])->get(["id", "name"])->toArray(); //不为空时 if(!empty($list)){ foreach($list as $key => $item){ //取出该学院下的专业 $speciality = Speciality::query()->where([ "status" => Speciality::STATUS_YES, "secondary_college_id" => $item["id"], ])->get()->toArray(); //专业ID $specialityIds = array_column($speciality, "id"); //二级学院已录入的学生 $importStudents = AdmissionNewStudents::query()->where([ "annual_session" => $config->data, "status" => AdmissionNewStudents::STATUS_YES, "is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES, "sex" => AdmissionNewStudents::MALE, ])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray(); if(!empty($importStudents)){ $idcardList = array_column($importStudents, "idCard"); //根据身份证集取出已注册的用户 $userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray(); if(!empty($userList)){ $userList = array_column($userList, "unique_number"); //线下迎新有几步 $stepCount = OfflineStep::query()->where("status", OfflineStep::STATUS_YES)->count(); //检测是否存在线下报到步骤,存在则视为已到校(实际报到学生) $completedOfflineStep = CompletedOfflineStep::query()->whereIn("unique_number", $userList)->where("annual_session", $config->data)->where("step_id",">=",$stepCount)->count(); $studentsNum = count($importStudents); //报到率 if($completedOfflineStep == 0 || $studentsNum == 0){ $registering = 0; }else{ $registering = round((($completedOfflineStep / $studentsNum) * 100), 2) ; } $list[$key]["registering"] = $registering; $list[$key]["studentsNum"] = $completedOfflineStep; $list[$key]["completedOfflineStep"] = $studentsNum; } } } foreach($list as $item){ array_push($label, $item["name"]); if(!empty($item["registering"])){ array_push($data[0]["data"], $item["registering"]); array_push($data[0]['tooltip'][0]['data'], $item["studentsNum"]); array_push($data[0]['tooltip'][1]['data'], $item["completedOfflineStep"]); }else{ array_push($data[0]["data"], 0); array_push($data[0]['tooltip'][0]['data'], 0); array_push($data[0]['tooltip'][1]['data'], 0); } } } $this->option("series",$data); $this->option("labels",$label); $this->option("yaxis",["max" => 100]); //Y轴最大值 $tooltipCustomFunction = <<{ newStr += `
\${item.name}: \${item.data[dataPointIndex]}
` }) return `
\${w.config.labels[dataPointIndex]}
\${w.config.series[0].name}: \${w.config.series[0].data[dataPointIndex]}
\${newStr}
`; } JS; $this->option('tooltip.custom', JavaScript::make($tooltipCustomFunction)); } }