|
|
|
Forum 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>"; |
|
|
|
|
|
Supreme Being
      
Group: Moderators
Last Login: 10/11/2008 2:58:00 AM
Posts: 811,
Visits: 1,289
|
|
| Hi, Could you please try setting color attribute to <dataset> element if you with to give each dataset a separate color? You can also use color attribute in each <set> element which would set color for each dataplot of your chart.
Regards,
Sudipto Choudhury FusionCharts Team
|
|
|
|
|
Forum 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?
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44,
Visits: 93
|
|
| please tell me solution for the above query or question? or haven't you got my question?
|
|
|
|
|
Supreme Being
      
Group: Moderators
Last Login: 10/11/2008 2:58:00 AM
Posts: 811,
Visits: 1,289
|
|
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. Could you please see the Code samples using this function in folders Code >> PHP >> Array Examples / DBExample etc. |
Regards,
Sudipto Choudhury FusionCharts Team
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44,
Visits: 93
|
|
| Thanks for reply. I made the changes you suggested. Now it works fine.
|
|
|
|