couldn't you make changes to you code that you have provided in particualr thread.
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



couldn't you make changes to you code that... Expand / Collapse
Author
Message
Posted 4/29/2008 2:58:22 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
Suggestion that you have made( could you please download the FusionWidgets Blueprint Application code and refer to function buildXMLMonthlyRev() in DataGen.php) contains following code:

$MonthArray=array();
 while($oRs=mysql_fetch_array($result)){
     $MonthArray[$oRs['Month']]=$oRs['TotalSales'];
  
 }
 // we again retireve the monthly revenue value form array and create set XML elements for each month
 for($i=1;$i<=12;$i++){
  $strXML .= "<set value='" . $MonthArray[$i] . "' />";
 }

Instead of $strXML I have used $strCat .

Means you have used for loop out of while loop.

In our categorywise sales example, you have used mysql_data_seek() function. I made

changes to the my code as per above code. But because of this for loop( which out of while loop) it does not display proper labels (means month labels) & I think this is because of

we are using mysql_data_seek($resultCat) . Could'nt you make changes to the your code?

(even though As my need is a bit different from the original design you had)

Post #5997
Posted 4/29/2008 4:30:37 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Moderators
Last Login: Today @ 1:21:47 AM
Posts: 675, Visits: 1,079
Hi,

Could you please check if this code helps :

//getCumulativeSalesByCatXML returns the cumulative sales for each category
//in a given year
function getCumulativeSalesByCatXML($intYear, $forDataURL) {

    // Function to connect to the DB
    $link = connectToDB();

    //To store categories - also flag to check whether category is
 //already generated
 
 //Initialize XML elements
 //Categories
 $strCat = "<categories>";
 for($mn =1;$mn<=12;$mn++){
  //Add this category as dataset
  $strCat .= "<category label='" . date("F",mktime(0,0,0,$mn,2,1994)) . "' />";
 }
 
 $strCat .= "</categories>";
  
 
 
 //First we need to get unique categories in the database
 $strSQL = "Select CategoryID,CategoryName from FC_Categories GROUP BY CategoryID,CategoryName";
    $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='" . escapeXML($orsCat['CategoryName'],$forDataURL) . "'>";
   
    
    //Now, we need to get monthly sales data for products in this category
    $strSQL = "SELECT  Month(o.OrderDate) as MonthNum, g.CategoryID, g.CategoryName, ROUND(SUM(d.Quantity),0) as Quantity, SUM(d.Quantity*p.UnitPrice) As Total FROM FC_Categories as g,  FC_Products as p, FC_Orders as o, FC_OrderDetails as d  WHERE year(o.OrderDate)=" . $intYear ." and g.CategoryID=" . $orsCat['CategoryID'] . " and d.ProductID=p.ProductId and g.CategoryID= p.CategoryID and o.OrderID= d.OrderID GROUP BY g.CategoryID,g.CategoryName,Month(o.OrderDate) order by Month(o.OrderDate)";
    //Execute it
    $result2 = mysql_query($strSQL) or die(mysql_error());
    $MonthArray=array();
    while($ors=mysql_fetch_array($result2)){
     $MonthArray[$ors["MonthNum"]]=$ors['Total'];
    }
    for($i=1;$i<=12;$i++){
     if($MonthArray[$i]){
     $strLink = urlencode("updateProductChart(" . $intYear . "," . $i . "," .$orsCat['CategoryID'] . ");");
     $strDataXML .= "<set value='" . $MonthArray[$i] . "' link='" . $strLink . "'/>";
      
     }else{ 
      $strDataXML .="<set value=''/>";
     }
    }
   
    //Clear up objects
    mysql_free_result($result2);
        //Close dataset element
        $strDataXML .= "</dataset>";
   }
    }
    mysql_close($link);

 //Create full XML
 $strXML = $strCat . $strDataXML;

    //Return
 return $strXML;
}

Regards,

Sudipto Choudhury
FusionCharts Team

Post #5998
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -7:00, Time now is 9:45pm


Execution: 0.172.