I am trying to make a chart with 1 column for each content type. Values are the addition of each total.

I have created a view (using the Views module) with two content-type fields. One of them is configured to Count Distinct in aggregation.

In a graph, however, only one column named Type appears, and not a column for each content type.

I am trying both with Views Dataviz and Google Charts Tools.

Any help on this would be appreciated.

  • More information needed. Consider writing a custom module. Always works. The Visualization API is very promising for such kind of work. Jul 5, 2013 at 12:45

2 Answers 2


Let me try to answer this if I am getting you clearly. There are several contributed modules available for creating charts in Drupal. Refer to the comparison of charting modules for more details. You are not specifying the Drupal version, let me assume a use case for 7. Also know that there are various types of licenses (commercial, open source, ...) for each of the charting libraries, so your choices may be limited by your license needs (each module typically requires at least 1 such charting library as its charting engine).

The solution I am giving has a lot to do with the Google Charts API implemented via the Google Chart Tools module. The module provides a simple API that allows you to build your graphs on that.The module ships with an example that gives a nice pointer to writing your own custom module.

A simple module to get the content types.

function example_block_info(){
  //lets display this in a block. You can do a page if you like.
  $blocks['example_chart'] = array(
     'info' => t('Example Line Bar Showing Content Types'),
     'cache' => DRUPAL_CACHE_PER_ROLE //This is a Drupal default.You can set your own.
 return $blocks;

function example_block_view($delta = ''){
    //Create a display for the block.
    switch ($delta) {
      case 'example_chart':
       $block['content'] = example_block_contents()
  return $block;

function example_block_contents(){
  //This is a function specific to the block that lets you prepare the content for the chart.
    //Google Chart Tools integration begins here.
    //First empty the array that is to be passed to draw_chart().
    $settings = array();
    //We then populate the array.
    $settings['chart']['Chart for Nodes'] = array(
      //I am using just one content type. You can loop to get the other node types.
      'header' => array('My Node'),
      //This is the array to be presented to draw(). 
      'rows' => array(array(
      'chartType' => 'ColumnChart',
      'containerId' => 'example_chart',
      'options' => array(
            'forceIFrame' = FALSE,
            'title' => 'A column chart for nodes',
            'width' => 800,
            'height' => 600
    //Return the DIV containing the chart.
    return '<div id="example_chart"></div>';

function example_node_count(){
  //Custom function to count the nodes available.
  //Put to use Entity Field Query.
  $query = new EntityFieldQuery;
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'my_node_type');
    //Count your node type.Introduce a loop to count your other nodes as needed.
    $my_node_type_count = $query->count()->execute();
    return $my_node_type_count;

This is just a shell of a working module. Get some education of the charts at Google Visualization API docs. Warning: There might be some typos in there. Just trying to give an alternative.


I seem to understand that this question is exactly what the purpose is of one of the Out-of-the-box examples that you get by simply installing (and enabling) the Charts module, and without any additional configuration.

By doing so, a new view is added to your site. Here are some more details about it, quoted from the linked page above (to which I added some formatting here):

You can see the charts created via this new view in your own site by navigating to charts/examples or by using a menu link with a title like Charts examples. After doing so, a page is shown with 2 sub-menu tabs:

  • the first tab is titled Built-in examples (this example is used to showcase Using the Charts API).
  • the second tab is titled Views example, and is what is created from the new view created during the installation of the charts module. As an alternative to using this tab, just navigate to charts/examples/views in your site. You should then see a column chart and a pie chart, which are followed by a tabular display also. Both charts and the table display contain data about the total number of nodes for each of the available content types.

Visit the Charts demo site for an online preview of these out-of-the-box examples.

Disclosure: I'm the maintainer of this module.

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.