-2

I downloaded fusion chart plug-ins and they work properly . but now when I integrate them with php mysql , the page draws the image but no data is displayed . I searched google since yesterday still no luck .Bellow is my code

<html>
    <head>
    <html>
    <head>
    <title>My first chart using FusionCharts Suite XT</title>
    <script type="text/javascript" src="js/fusioncharts.js"></script>
    <script type="text/javascript" src="fusioncharts/themes/fusioncharts.theme.fint.js"></script>
    <script type="text/javascript">
      FusionCharts.ready(function(){
        var revenueChart = new FusionCharts({
            "type": "column2d",
            "renderAt": "chartContainer",
            "width": "500",
            "height": "300",
            "dataFormat": "json",
            "dataSource":  {
              "chart": {
                "caption": "Monthly revenue for last year",
                "subCaption": "Harry's SuperMart",
                "xAxisName": "Month",
                "yAxisName": "Revenues (In USD)",
                "theme": "fint"
             },

             "data": [

                <?php
    //This Code is working 100% 2013-09-06 3:27 pm King Musa in Benoni
       include_once("pdo.inc.php");
    $query ="select  a.brno,(select name from branch where code = a.brno) as branchName, sum(a.sls) as 'actual sls', sum(b.bsls) as'budget sls' , sum(b.psls) as'previous sls'  from dslssum a,budfile b
    where a.period = '201401' and a.brno = b.brno and a.period = b.period
    group by a.sls desc limit 0,10
    ";
        $result_query = $con->prepare($query);
        $result_query->execute();
         //$num_clents = $result_query->fetchColumn();
    // Branch number , Branch name , actual sales , Budget sales , Previous Sales 
    // declare the arrays 
    $branch_no_array = array(); // String 
    $branch_name_array = array(); // string 
    $actual_sales_array = array(); // double 
    $budget_sales_array = array(); // double 
    $Previous_sales_array = array();  // double 
    //declare the arrays  ends 

    $data [] = Array ("Branch Name","Actual Sales");
    while($row = $result_query->fetch(PDO::FETCH_ASSOC)){
    extract($row);
    //NEW CODE IT WHATS U TO CREATE FOREACH LOOP FOR EACH VALUE 
    //Finished it with my Eastage friend 07:30 PM 2013-09-28
    $branch_No =  $row['brno'];
    $branch_Name =  $row['branchName'];
    $actual_sales = $row['actual sls'];
    $budget_sales = $row['budget sls'];
    $previous_sales = $row['previous sls'];


    // fill the arrays Musa 
    $branch_no_array = array($branch_No);
    $branch_name_array = array($branch_Name);
    $actual_sales_array = array($actual_sales);
    $budget_sales_array = array($budget_sales);
    $Previous_sales_array = array($previous_sales);

    foreach($branch_no_array as $branchNo){

    foreach($branch_name_array as $namesName){
    foreach($actual_sales_array as $key){
    $actualSales = intval($key);

    foreach($budget_sales_array as $final_budget){
    $budgetSales = intval($final_budget);

    foreach($Previous_sales_array as $prev_sales){
    $previousSales = intval($prev_sales);
    ////////////second 4ea

    ?>
    <?php 

        $data []= Array ($namesName ,$actualSales);

    }}}}}}
        $table = json_encode($data);
        echo $table ; // this line is important it should be not disabled 

    ?>       

              ]
          }

      });
    revenueChart.render();
    })
    </script>
    </head>
    <body>
      <div id="chartContainer">FusionCharts XT will load here!</div>
    </body>
    </html>

1 Answers1

0

Since data is being retrieved from MySQL database, data can be generated by iterating through each record and store it in strXML variable the chart should be echoed out using the renderchart() method and pass strXml as dataStr.

You can refer the FusionCharts documentation for rendering charts using PhP and mysql. http://docs.fusioncharts.com/charts/contents/guide-for-web-developers/php/PHP_DB.html

Swarram
  • 383
  • 2
  • 4