Multiple Charts in a Single View

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
As If's picture

This is a bit of a hack, but I'm experimenting with ways to get multiple statistics charts into a View. I know I could just write function calls to charts.googleapis directly, but I like the way the Quiz charts look and I was hoping to be able to leverage them easily. The chart I'm particularly interested in (for this View) is the "Status" piechart.

So I created a Block View that pulls up the nid and vid for each Quiz in a Group (my site is using OG, and Quizzes are created by group admins for their own group members). I excluded both of these fields from the display, and added a custom text field to generate/display the output. Then I created a field template for that third field that looks like this:

$nid = $row->nid;
$vid = $row->node_revision_vid;
// Note: We must include quiz_stats.admin.inc so we can use its functions.
require_once DRUPAL_ROOT . '/sites/all/modules/quiz/includes/quiz_stats/quiz_stats.admin.inc';
$charts[$vid] = array();
$charts[$vid]['status'] = _get_quiz_status_chart($vid);
echo theme('quiz_stats_charts', array('charts' => $charts[$vid]));

When I have only one Quiz in the View this works perfectly, and the Status piechart is displayed. But here's the problem: When there are 2 or more Quizzes in the same View, the first piechart shows up for all of them.

The vids are different, I can do a print_r() inside the field template and see them, or I can do a print_r() inside theme_get_quiz_status_chart() and I can see them there too. So the Quiz functions and my templates are receiving the correct data. The problem seems to come when the call is made to charts.googleapis. All items in the View end up formulating the same query string, and therefore delivering the same image (the first one in the View). (See attached PNG.)

Does anybody have any ideas about individuating these calls, so more than one Status chart can be displayed on a single page?

TIA!

AttachmentSize
quizzes_in_view.png550.38 KB

Quiz

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week