0
我試圖在使用JSON和php從我的數據庫中導入我的數據的Fusion圖表中生成msline圖表,但我無法繪製數據,這意味着圖表無法正確顯示。Fusion圖表 - 使用JSON和數據庫的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
我需要的圖表,以產生是RoundNo在x軸上和兩個dataseries一個用於「東珀斯」與值41,109和115以及一個第二系列稱爲「對手」具有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個系列而不是2個系列。嘗試先手動創建數據結構,然後再匹配您的邏輯。 – pallabB
感謝pallabB - 我已經完成了這一切,似乎無法讓它工作,就像我想這樣做。我已經編輯我的查詢和上面的代碼沒有運氣 - 我已經根據它關於融合圖表 – waflfootyfacts
的「工廠」例如這是它應該如何看 - http://jsfiddle.net/BQUw4/61/ – waflfootyfacts