Question

i make a fusionchart and i add 3 links to show charts but i want to show one chart at a time,how i do this?i make a fusionchart and i add 3 links to show charts but i want to show one chart at a time,how i do this?here is my code:

 <?php
 $title='Product Management';
 include("merchantheader.php");
 include("DBConn.php");
 include("FusionCharts.php");
 $link = connectToDB();
 $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";
    $result = mysql_query($strQuery) or die(mysql_error());
    $strXML = "<chart caption='Reports of transactions' showValues='0' useRoundEdges='1' palette='3'>";
    while($ors = mysql_fetch_assoc($result)){
    //Generate <set label='..' value='..' />
    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
    }
    //free the result set
    //mysql_free_result($result);
    //mysql_close($link);
    //Finally, close <chart> element
    $strXML .= "</chart>";

    //date_default_timezone_set($_SESSION['timezone']);
 ?>
 <?php 
    $query="SELECT Min(transaction_date) as start,Max(transaction_date) as end from transactions";
    $result1= mysql_query($query) or die(mysql_error());
    $ors1=mysql_fetch_array($result1);
    $startdate= $ors1['start'];
    $enddate=$ors1['end'];
 ?>
 <?php
 function past7days(){
    $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions where transaction_date BETWEEN current_date()-7 AND current_date() group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";
    $result = mysql_query($strQuery1) or die(mysql_error());
    $strXML = "<chart caption='Reports of transactions' showValues='0' useRoundEdges='1' palette='3'>";
    while($ors = mysql_fetch_assoc($result)){
    //Generate <set label='..' value='..' />
    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
    }
    //free the result set
    //mysql_free_result($result);
    //mysql_close($link);
    //Finally, close <chart> element
    $strXML .= "</chart>";

    //date_default_timezone_set($_SESSION['timezone']);

  }
  function past14days(){
    $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions where transaction_date BETWEEN current_date()-14 AND current_date() group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";
    $result = mysql_query($strQuery1) or die(mysql_error());
    $strXML = "<chart caption='Reports of transactions' showValues='0' useRoundEdges='1' palette='3'>";
    while($ors = mysql_fetch_assoc($result)){
    //Generate <set label='..' value='..' />
    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
    }
    //free the result set
    //mysql_free_result($result);
    //mysql_close($link);
    //Finally, close <chart> element
    $strXML .= "</chart>";

    //date_default_timezone_set($_SESSION['timezone']);

 }
  function past30days(){
    $strQuery="select Distinct DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y') as transaction_date,sum(amount)as Amount from transactions where transaction_date BETWEEN current_date()-30 AND current_date() group by  DATE_FORMAT(transactions.transaction_date,'%c-%d-%Y')";
    $result = mysql_query($strQuery1) or die(mysql_error());
    $strXML = "<chart caption='Reports of transactions' showValues='0' useRoundEdges='1' palette='3'>";
    while($ors = mysql_fetch_assoc($result)){
    //Generate <set label='..' value='..' />
    $strXML .= "<set label='" .$ors['transaction_date'] ."' value='" . $ors['Amount'] ."' />";
    }
    //free the result set
    //mysql_free_result($result);
    //mysql_close($link);
    //Finally, close <chart> element
    $strXML .= "</chart>";
    //date_default_timezone_set($_SESSION['timezone']); 
  }
  ?>

    <!-- Include FusionCharts.js to provide client-side interactivity -->
    <script type="text/javascript" src="<?=MURL?>/Charts/FusionCharts.js"></script>  
    <link href="<?=MURL?>/assets/ui/css/style.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="<?=MURL?>/assets/ui/js/jquery.min.js"></script>
    <script type="text/javascript" src="<?=MURL?>/assets/ui/js/lib.js"></script>   
    <h1 style="margin-top:24px;"><?=ucfirst($_GET['page5'])?><? if($_POST['mode']=='test' || $_GET['mode']=='test') { print " (Test Mode)"; } ?></h1>

   <p class="right_align">
<!--<a href="/merchant/products/1/manage/transactions?cmd=search&mode=<?=$_GET['mode']?>" class="blink search">Search</a>

   <a href="javascript:void(0)" class="blink refresh" onclick="location.reload();">Refresh</a>-->

<a href="/merchant/products/1/manage/reports?cmd=compare&mode=<?=$_GET['mode']?>" class="blink chart" >Compare Events</a>
   </p>
   <p align="left" style="color:#000"><?php echo date('M dS Y' ,strtotime($startdate)); ?> to <?php echo date('M dS Y' ,strtotime($enddate)); ?><a href="#" style="color:#00F; margin-left:15px; text-decoration:underline">Past 7 Days</a><a href="#" style="color:#00F; margin-left:15px; text-decoration:underline">Past 14 Days</a><a href="#" style="color:#00F; margin-left:15px; text-decoration:underline">Past 30 Days</a><a href="#" style="color:#00F; margin-left:15px; text-decoration:underline">Set A Custom Data Range</a><span class="right_float links">
  MODE
 <select id="mode" name="mode">
 <option value="live">Live</option>
 <option value="test">Test</option>
 </select>
 </span></p>
 <div id="chartContainer">
 <?php
 FC_SetRenderer('javascript');
 echo renderChart('Charts/Line.swf', // Path to chart type
                '',         // Empty string when using Data String Method
                $strXML,    // Variable that contains XML string
                'Tracking', // Unique chart ID
                '850', '400', // Width and height in pixels
                false,      // Disable debug mode
                true        // Enable 'Register with JavaScript' (Recommended)
            );
  ?>
  </div>  
Was it helpful?

Solution

AS per your requirement, you could follow the below mentioned steps:

a. Call your own PHP function on "onClick" event of HTML anchor tag, which will generate the required XML (as you have already done).

b. Then call another function (after generating required XML string) which will generate the chart using the provided XML data, in "renderChart()" method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top