I'm trying to make a Bar chart with multiple sections to it

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Raissam on 28th February 2014
Hi there,

Just trying to do a graphic bar with 3 parameters coming from sql.. but the bars dont stack.. i get one mess value.


     $result = mysql_query("Select Status_do_Case, ano, count(cases) as Total_Cases FROM cases GROUP BY Ano , Status_do_Case" );
     if ($result) {
         $data1 = array();
         $data2 = array();
         $labels = array();
         while ($row = mysql_fetch_assoc($result)) {
             $data1[] = $row["Status_do_Case"];
             $data2[] = $row["Total_Cases"];
             $labels[] = $row["ano"];

         // Now you can aggregate all the data into one string
         $data1_string = "['" . implode("', '", $data1) . "']";
         $data2_string = "['" . implode("', '", $data2) . "']";
         $labels_string= "['" . implode("', '", $labels). "']";

         window.onload = function ()
             var bar = new RGraph.Bar('cvs', [<?php print($data2_string) ?> , <?php print($data1_string) ?>])


                 .Set('labels', <?php print($labels_string) ?>)
Posted by Richard on 28th February 2014
Hi there,

Your PHP variables might not contain exactly what you think. See what the error is in your JavaScript console and then cross-reference that with the (HTML) source.

Posted by Raissam on 7th March 2014
no way to get stacked bars :/

my problem is the correct format of database infos.

how i format the result of my query?

my x axis is year..

on y axis i have the quantity and itens.. but on demo you show the y like that [[2,3,4],[2,4,5]] and i dont know how i fetch result to get something like this.
Posted by Richard on 10th March 2014
Hi there,

You might get the result of your SQL query to look something like this:

SELECT `year`, q1 AS `quantity1`,q2 AS `quantity2`,q3 AS `quantity3` FROM foo

You could use subqueries or joins to get the quantities - subqueries might be easier but could be slower - but if your site isn't massively busy you might not notice the difference.

You'd then end up with a result set that you can easily work with and getting a row from the result set would give you all of the values for a single stacked bar.


Add a reply

« Back to message list