如何使用多个图表数据来显示fusionchart?

时间:2014-01-27 13:42:59

标签: php jquery charts fusioncharts

我做了一个fusionchart,我添加3个链接来显示图表,但我想一次显示一个图表,我是怎么做的?我做了一个fusionchart,我添加3个链接来显示图表,但我想显示一个图表我一个人怎么做?这是我的代码:

 <?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>  

1 个答案:

答案 0 :(得分:0)

根据您的要求,您可以按照以下步骤进行操作:

一个。在HTML锚标记的“onClick”事件上调用自己的PHP函数,这将生成所需的XML(正如您已经完成的那样)。

湾然后在“renderChart()”方法中调用另一个函数(在生成所需的XML字符串之后),该函数将使用提供的XML数据生成图表。