【问题标题】:Fusion charts - msline chart using JSON with databaseFusioncharts - 使用 JSON 和数据库的折线图
【发布时间】:2016-07-03 23:59:19
【问题描述】:

我正在尝试使用 JSON 和 php 在 Fusion Charts 中生成 msline 图表以从我的数据库中导入我的数据,但在绘制数据时遇到了问题,这意味着图表无法正确显示。

在此处查看输出:www.waflfootyfacts.net/charttest2.php

我的数据库例子是这样的;

|Team |RoundNo | Total
|East Perth | R1 | 41 
|East Fremantle | R1 | 96
|East Perth | R2 | 109 
|Swan Districts | R2 | 96
|East Perth | R3 | 115 
|Subiaco | R3 | 51

我需要图表生成的是 x 轴上的 RoundNo 和两个数据系列,一个用于“East Perth”,值为 41、109 和 115,第二个系列名为“Opponent”,值为 96,96 和 51 .

我的图表正在生成,但未正确计算系列。

我的代码

// Form the SQL query

   $strQueryCategories = "SELECT RoundNo FROM MatchDetails  WHERE (Team = 'East Perth' OR Opponent = 'East Perth') AND Season = 2015 AND RoundNo IN ('R1', 'R2', 'R3')";

$resultCategories = $dbhandle->query($strQueryCategories)or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");

$strQueryData = "SELECT Team, RoundNo, Total FROM MatchDetails  WHERE (Team = 'East Perth' OR Opponent = 'East Perth') AND Season = 2015 AND RoundNo IN ('R1', 'R2', 'R3')";


$resultData = $dbhandle->query($strQueryData)or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");

if ($resultData) {

    $arrData = array(
        "chart" => array(
            "caption" => "East Perth in 2015",
            "subcaption" => "Scores For & Against",
            "theme" => "fint"
        )
    );

    $arrData["categories"] = array(array("category" => array()));


    if ($resultCategories) {
        $controlBreakValue = "";
        while ($row = mysqli_fetch_array($resultCategories)) {
            if ($controlBreakValue != $row["RoundNo"]) {
                $controlBreakValue = $row["RoundNo"];
                array_push( $arrData["categories"][0]["category"], array("label" => $controlBreakValue));
                $controlBreakValue == "";
            }
        }
    }


    $arrData["dataset"] = array();
    $i = 0;
    if ($resultData) {
        $controlBreakValue = "";
        while ($row = mysqli_fetch_array($resultData)) {
           if ($controlBreakValue != $row["Team"]) {
               $controlBreakValue = $row["Team"];
               array_push($arrData["dataset"], array("seriesname" => $controlBreakValue, "data" => array(array("value" => $row["Total"]))));
               $controlBreakValue == "";
               $i++;
                   }  
            array_push($arrData["dataset"][$i - 1]["data"], array("value" => $row["Total"]));

              }
            }
    }

$jsonEncodedData = json_encode($arrData);

$dbhandle->close();

echo $jsonEncodedData;

?>

<html>


   <body>
      <?php

        $columnChart = new FusionCharts("msline", "" , 300, 300, "chart-1", "json", $jsonEncodedData);

            $columnChart->render();

      ?>

      <div id="chart-1"><!-- Fusion Charts will render here--></div>

   </body>

</html>

【问题讨论】:

  • 问题不在于图表,而在于您的逻辑。从实现中,您创建了 3 个系列而不是两个系列。尝试先手动创建数据结构,然后匹配您的逻辑。
  • 感谢 pallabB - 我已经这样做了,但似乎无法让它像我想要的那样工作。我已经编辑了上面的查询和代码,但没有成功 - 我基于融合图表上的“工厂”示例
  • 这是应该的样子 - jsfiddle.net/BQUw4/61
  • 我现在已经设法让它几乎正确。我现在唯一的问题是每个系列中的第一个值都被复制为第一个和第二个值,第二个值显示为第三个值,第三个值根本没有显示在图表上
  • 由于您已经更改了逻辑,因此很难猜测,但根据我的经验,应该是您如何迭代循环的问题。仔细检查循环中的初始化和增量过程。

标签: javascript php json charts fusioncharts


【解决方案1】:

所有排序 - 最终不是我的错误,但融合图表提供的 php 包装器是错误的 - 他们给我发了一个新的并且它有效!

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多