Webフォームの結果をGoogleグラフとして表示しようとしています。私は、テーマのtemplate.phpファイルでtheme_webform_results_analysis()をオーバーライドし、Chartモジュールを使用して、テーマレイヤーでこれを行っています。Drupal 6.22、Webform 6.x-3.11。
通常、webform分析ページはデータをテーブルに表示するので、そのテーブルの配列をハックして、Chart APIにデータを渡します。
編集:私はvar_dumpの使用方法を理解し、$ row_dataと$ questionsの配列を別々に取得する方が良い方法だとわかりました(この質問の最初のバージョンにあった$ rows配列を使用する代わりに、両方の配列のマッシュアップ)。
編集#2:元の$ questionsおよび$ row_data配列の各部分を取得する方法を発見したと思います(以下を参照-他のforeachのforeach)。だから今私はそれらのピースを適切な配列に入れ(質問ごとに1つ)、それらすべてを反復する方法を見つける必要があります。
これがtemplate.phpにあるものです:
/**
 * Output the content of the Analysis page.
 * @see webform_results_analysis()
 */
function mytheme_webform_results_analysis($node, $data, $sids = array(), $analysis_component = NULL) {
  foreach ($data as $cid => $row_data) {
    if (is_array($row_data)) {
      // get the questions, put them in an array
      $questions = array();
      $questions[] = array('data' => check_plain($node->webform['components'][$cid]['name']));
      // this will print everything out in the right order - it really needs to
      // make an array for each question that looks like $test_chart below
      foreach ($questions as $question) {
        print $question['data'] . '<br />'; // questions 
        foreach ($row_data as $key => $value) {
          print $value[0] . '<br />'; // labels
          print $value[1] . '<br />'; // results 
        }
      }
      // Set up the chart
      $chart = array(
        '#chart_id' => 'webform_analysis',
        '#type' => CHART_TYPE_PIE_3D,
        '#size' => chart_size(658, 250)
      );
      // not real data here, this just shows the format I'm shooting for
      $test_chart = array(
        'option 1' => '12',
        'option 2' => '45',
        'option 3' => '122'
      ); 
      // separate the above array into labels and values, add a percentage to the label
      foreach ($test_chart as $key => $value) {
        $chart['#data'][] = $test_chart[$key];
        $chart['#labels'][] = strip_tags($key) . ' (' . round($test_chart[$key], 2) .  '%)';
      }
      // pick some colors
      $chart['#data_colors'][] = 'b0c73d';
      $chart['#data_colors'][] = '667323';
      $chart['#data_colors'][] = '221f1f';
      $output = chart_render($chart);    
    }
  }
  if (count($row_data) == 0) {
    $output = t('There are no submissions for this form.');
  }
  // return the data that goes into chart function, just for testing
  // return $chart_data; 
  // someday, this might return a set of webform charts. right now it returns the fake test chart
  // return $output;
}