Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-1306

add pie charts to reports

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.2
    • Fix Version/s: 1.9.2
    • Component/s: Module: Questionnaire
    • Labels:
      None
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      enabling embedded (on the fly generated) pie chart graphs
      when viewing reports of multiple choose questions.
      (a link to the original patch : http://tracker.moodle.org/browse/MDL-19054)

      1. get the code of the pie chart image generator from : http://www.peters1.dk/webtools/php/lagkage.php?sprog=en
      copy that file and put it into moodle/lib (call it makechart.php)

      2. i am pasting the affected and changed function here.

      new added lines are marked (at the end of the line) with // add this line to patch

      function display_resp_single_results($rids=false, $guicross=false) {
              echo clean_text($this->content).'</div>';
              if (is_array($rids)) {
                  $prtotal = 1;
              } else if (is_int($rids)) {
                  $prtotal = 0;
              }
      	$response_pie_data = '';    // add this line to patch
      	$response_pie_data_label = '';  // add this line to patch
              if ($rows = $this->get_response_single_results($rids)) {
                  foreach ($rows as $idx => $row) {
                      if (strpos($idx, 'other') === 0) {
                          $answer = $row->response;
                          $ccontent = $row->content;
                          $count = $row->num;
                          $content = preg_replace(array('/^!other=/', '/^!other/'),
                                  array('', get_string('other', 'questionnaire')), $ccontent);
                          $content .= ' ' . clean_text($answer);
                          $this->counts[$content] = $count;
                      } else {
                          $contents = choice_values($row->content);
                          $this->choice = $contents->text.$contents->image;
                          $count = $row->num;
                          $this->counts[$this->choice] = $count;
                      }
      	    $response_pie_data .= $row->num.'*';    // add this line to patch
      	    $response_pie_data_label .= $row->num.'*';    // add this line to patch
                  }
      	    $response_pie_data = rtrim($response_pie_data,'*');    // add this line to patch
      	    $response_pie_data_label = rtrim($response_pie_data_label,'*');    // add this line to patch
                  $this->mkrespercent(count($rids), $this->precise, $prtotal, $guicross);
      	    echo '<img src="/moodle/lib/makechart.php?data='.$response_pie_data.'&label='.$response_pie_data_label.'" />';   // add this line to patch
              } else {
                  print_string('noresponsedata', 'questionnaire');
              }
          }

        Attachments

          Activity

            People

            Assignee:
            rezeau Joseph Rézeau
            Reporter:
            nadavkav Nadav Kavalerchik
            Participants:
            Component watchers:
            Mike Churchward
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              11/Jul/08