I am using Google Charts API module to generate a pie chart of a content type with the fields Blood-group and count representing the sectors.

For this I need to completely alter the query (= select from a different table) that the views integration provides.

My question: Can I use hook_views_query_alter?

  • Yes you can. Post the code which you are trying..
    – RajeevK
    Commented Jul 5, 2013 at 11:02
  • Hmmm. Found it easier to write my own custom module. Greater flexibility. Charting with views on 7 hasn't been really good to me. Commented Jul 5, 2013 at 12:38
  • I havent tried with query_alter. In my chart_views module, I added the function chart_views_views_pre_execute() { if($view->name=="charts") { $view->build_info['query']="select field_blood_group_value,count(*) from field_data_field_blood_group group by field_blood_group_value"; } } However, this gave me an Ajax 500 error Thank you
    – Anupama
    Commented Jul 5, 2013 at 17:43

1 Answer 1


To create charts in Drupal, there are plenty of modules available. Refer to the comparison of charting modules for an overview. After doing so, it should be clear that the names (and namespaces) of various charting modules are pretty confusing. Therefor I suggest you add a link to the exact 'Google Charts API' module this question is about.

Moreover, if I correctly understand the question, it seems to me that this is a rather straight forward requirement that can be easily addressed with (at least) the Charts module, i.e. the views integration of it (provides a new views style plugin to transform tabular view results into a chart). I recently created quite a lot of new Charts documentation that should help to get started with it.

The Charts module ships with out-of-the-box samples which are straight forward to adapt to fit your needs, e.g. by cloning these samples in a new views display or a new view. Of course there are other alternatives in that comparison that might be a better fit for this specific case.

Be aware: I'm a new (co-) maintainer of both Chart and Charts (confusing module names, I didn't invent them), and the author of the comparison of charting modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.