【问题标题】:How can I display data from mysql using php into fusion chart如何使用 php 将 mysql 中的数据显示到融合图中
【发布时间】:2015-02-05 03:06:08
【问题描述】:

我下载了融合图表插件,它们可以正常工作。但现在当我将它们与 php mysql 集成时,页面绘制图像但没有显示数据。我从昨天开始搜索谷歌仍然没有运气。下面是我的代码

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

【问题讨论】:

    标签: php jquery mysql fusioncharts


    【解决方案1】:

    由于数据是从 MySQL 数据库中检索的,因此可以通过遍历每条记录来生成数据并将其存储在 strXML 变量中,因此应使用 renderchart() 方法回显图表并将 strXml 作为 dataStr 传递。

    您可以参考 FusionCharts 文档使用 PhP 和 mysql 渲染图表。 http://docs.fusioncharts.com/charts/contents/guide-for-web-developers/php/PHP_DB.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 2014-07-14
      • 2012-12-13
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多