|
|
|
Forum Member
      
Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44,
Visits: 93
|
|
| 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']."' color ='3300FF'>";
//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: 2 days ago @ 9:41:33 AM
Posts: 809,
Visits: 1,285
|
|
| Hi, I find, you already have added color to dataset: $strDataXML .= "<dataset seriesName='".$orsCat['ids']."' color ='3300FF'>"; You can also add color to each bar individually by using color in <set> element.
Regards,
Sudipto Choudhury FusionCharts Team
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44,
Visits: 93
|
|
| can you tell me where to use set element in example I have given? please
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 4/29/2008 4:06:17 AM
Posts: 44,
Visits: 93
|
|
| I am using only one set element in while loop in above example.
|
|
|
|