Hello,

I know it might not be the right place to post this,
but i have one question,

i would like to generate a chart,
that visualises my taxonomy terms from a vocabulary,
and counts how many nodes are posted in them,

just to get an overview of my site.

I'm not at all a php programmer,
but after 2days, i puzzled this together,
and i'm very shure, it is crappy, and not at all the good way to do this,

also, i would like that when i have a new taxonomy term, the charts gets updated automatically.

I used the javascript code from google, and not at all the php version of this module,
because i don't understand php enough,

can anyone please help?
Thanks
heres what i brewed lol :D


<?php

$count[ecology] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 7 AND n.status = 1
"));

$count[productdesign] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 5 AND n.status = 1
"));

$count[socialmedia] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 4 AND n.status = 1
"));

$count[technology] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 1 AND n.status = 1
"));

$count[urbanism] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 6 AND n.status = 1
"));

$count[video] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 2 AND n.status = 1
")); 
  
$count[webdesign] = db_result(db_query("
SELECT COUNT(*) 
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid = 3 AND n.status = 1
")); 


?>



<script language="javascript" src="http://www.google.com/jsapi"></script>  
 <div id="chart"></div>

          

<script type="text/javascript">
term1= <?php echo $count[term1]; ?>;
term2= <?php echo $count[term2]; ?>;
term3= <?php echo $count[term3]; ?>;
term4= <?php echo $count[term4]; ?>;
term5= <?php echo $count[term5]; ?>;
term6= <?php echo $count[term6]; ?>;
term7= <?php echo $count[term7]; ?>;

      var queryString = '';
      var dataUrl = '';

      function onLoadCallback() {
        if (dataUrl.length > 0) {
          var query = new google.visualization.Query(dataUrl);
          query.setQuery(queryString);
          query.send(handleQueryResponse);
        } else {
          var dataTable = new google.visualization.DataTable();
          dataTable.addRows(7);

          dataTable.addColumn('number');
          dataTable.setValue(0, 0, (ecology));
          dataTable.setValue(1, 0, (productdesign));
          dataTable.setValue(2, 0, (socialmedia));
          dataTable.setValue(3, 0, (technology));
          dataTable.setValue(4, 0, (urbanism));
          dataTable.setValue(5, 0, (video));
          dataTable.setValue(6, 0, (webdesign));

          draw(dataTable);
        }
      }

      function draw(dataTable) {
        var vis = new google.visualization.ImageChart(document.getElementById('chart'));
        var options = {
          chf: 'a,s,00000099|bg,s,00000000',
          chs: '420x270',
          cht: 'p3',
          chco: '7777CC|76A4FB|3399CC|3366CC|76A4FB|3399CC|3366CC',
          chd: 's:Uf9a',
             chdl: 'term|term|term|term|term|term|term',
          chp: '0.1',
          chl: '|||',
          chma: '|5',
          chof: 'png'
        };
        vis.draw(dataTable, options);
      }

      function handleQueryResponse(response) {
        if (response.isError()) {
          alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
          return;
        }
        draw(response.getDataTable());
      }

      google.load("visualization", "1", {packages:["imagechart"]});
      google.setOnLoadCallback(onLoadCallback);

    </script>


Comments

endreece’s picture

And thanks for this great module!!!

13rac1’s picture

Status: Active » Closed (won't fix)

This module doesn't currently (I hope it can in the future!) handle the Google Charts JS implementation, and I'm not familiar with it's use. You've got a good start there, but for now, you'll need to look for assistance elsewhere. Thank you!

Pierre.Vriens’s picture

The sample here contains some interesting sample with an SQL query, which some day might make it in the chart docu, hence the parent issue I'm adding now.