how to give different color for individual bar in multiseries bar chart.
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



how to give different color for individual... Expand / Collapse
Author
Message
Posted 4/21/2008 1:48:56 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44, Visits: 93
Following is the example of multiseries bar chart.That contains two series(two bars).

I want to give two different colors for that two bars.

I am preparing bar chart in php with mysql as database. Following is the php code

tell me where to give colour attribute in following code OR tell me which file to include?

   $strXML = "<graph caption='Factory  Output ' subcaption='(In Units)' xAxisName='Date' formatNumberScale='0' decimalPrecision='0' >";

    // Connet to the DB
   
 
   //To store categories - also flag to check whether category is already generated
   $catXMLDone = false;
 //Initialize XML elements
 $strCat = "<categories>";
 
 //First we need to get unique categories in the database
 $strSQL = "SELECT DISTINCT(p.product_type_id) as ids, Year(o.order_complete) as years FROM
order_items as oi, orders as o,products as p WHERE p.product_type_id >2 AND p.product_id = oi.product_id AND Year(o.order_complete) ='2008'  AND o.order_id = oi.order_id GROUP BY oi.product_id";


    $result = mysql_query($strSQL) or die(mysql_error());
 
  //To store datasets and sets
    $strDataXML = "";
 
   if ($result)
   {
        while($orsCat = mysql_fetch_array($result))
  {
            //Add this category as dataset
            $strDataXML .= "<dataset seriesName='".$orsCat['ids']."'>";

    //Now, we get the data for that factory
      $strSQL = "SELECT SUM(Total) as output,months1, years FROM(SELECT COUNT(oi.product_id) as Total, Month(o.order_complete) as months1 ,Year(o.order_complete) as years FROM order_items as oi, orders as o,products as p WHERE p.product_type_id = '".$orsCat['ids']."' AND p.product_id = oi.product_id AND Year(o.order_complete)='".$orsCat['years']."' AND o.order_id = oi.order_id GROUP BY months1) as chart GROUP BY months1";
     //Execute it
            $result2 = mysql_query($strSQL) or die(mysql_error());
            while($ors = mysql_fetch_array($result2))
    {
   //Append <category label=''> if not already done
                if (!$catXMLDone)
    {
                   $strCat .= "<category name='" .$ors['months1']. "' />";
               }
               //Append data
                 $strDataXML .= "<set value='" . $ors['output'] . "' />";
   }
            //Update flag that we've appended categories  
            $catXMLDone = true;
            //Clear up objects
            mysql_free_result($result2);
            //Close dataset element
            $strDataXML .= "</dataset>";
        }
    }
   // mysql_close($link);

    //Close </categories>
 $strCat .= "</categories>";
 //Create full XML
 $strXML .= $strCat.$strDataXML;

    //Return
 //return $strXML;

    //Close <graph> element
    $strXML .= "</graph>";

Post #5793
Posted 4/21/2008 1:49:39 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44, Visits: 93
I am using set element in while loop that while loop execute twice.

I have given color attribute in set element as follows

 $strDataXML .= "<set value='" . $ors['output'] . "'  color='ACD43F'/>";

but because of that while loop executed twice it shows the same color for both individual bars.

can you tell me solution?

Post #5794
Posted 4/21/2008 2:02:28 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: 2 days ago @ 4:15:20 AM
Posts: 772, Visits: 1,228
Hi,

Could you please use FC_Colors.php that we provide in the Includes folder inside folder : CODE >> PHP.

Using this you can use :

 getFCColor() function to sequentially generate colors from a list of 20 colors. Coudl you please see the Code samples using this function in folders  Code >> PHP >> Array Examples / DBExample etc.

Regards,

Sudipto Choudhury
FusionCharts Team

Post #5795
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -7:00, Time now is 5:42am


Execution: 0.063.