diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 1a7928b1b5936..598838eb8984c 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -28,6 +28,8 @@ use core_question\statistics\responses\analyser; use mod_quiz\local\reports\report_base; use core_question\statistics\questions\all_calculated_for_qubaid_condition; +use core\chart_pie; +use core\chart_series; require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); require_once($CFG->dirroot . '/mod/quiz/report/statistics/statistics_form.php'); @@ -432,7 +434,7 @@ protected function output_individual_question_response_analysis($question, $vari if ($this->table->is_downloading()) { $exportclass->output_headers($qtable->headers); } - + $chartdata = []; // Where no variant no is specified the variant no is actually one. if ($variantno === null) { $variantno = 1; @@ -442,6 +444,7 @@ protected function output_individual_question_response_analysis($question, $vari foreach ($subpart->get_response_class_ids() as $responseclassid) { $responseclass = $subpart->get_response_class($responseclassid); $tabledata = $responseclass->data_for_question_response_table($subpart->has_multiple_response_classes(), $partid); + $chartdata[] = ['label'=> $tabledata[0]->response, 'value' => $tabledata[0]->totalcount ]; foreach ($tabledata as $row) { $qtable->add_data_keyed($qtable->format_row($row)); } @@ -449,6 +452,21 @@ protected function output_individual_question_response_analysis($question, $vari } $qtable->finish_output(!$this->table->is_downloading()); + + // Extract labels and counts + $labels = array_column($chartdata, 'label'); + $counts = array_column($chartdata, 'value'); + + // Create the chart + $chart = new chart_pie(); + $series = new chart_series('Quiz Results', $counts); + + // Add series and labels + $chart->add_series($series); + $chart->set_labels($labels); + + // Render the chart in the report page + echo $OUTPUT->render($chart); } /**