【发布时间】:2018-05-24 23:01:17
【问题描述】:
我正在使用 MySQL/PHP 和 PHPWrapper 来使用 FusionCharts。我已经能够获取数据以将其呈现为 2D 列堆栈,但尽管有任何限制,但仍停留在 7。
我用它来显示从 4 月开始到 11 月的每个月的记录数,但是当我在 ASC 中按月对数据进行分组时,第一个堆栈从 5 月开始。有趣的是,当我将其更改为 DESC 时,我看到 OCt-Apr 的数据(7 条记录)而 11 月的数据丢失了。我没有定义任何可能会阻止它的限制,但我可以让它工作。
我在 MySQL 中的数据集类型是;
acqid - INT
acq_month - DATE
fusioncharts.php 及其相关的 JS 在文件中被正确调用。
以下是我正在使用的代码;
<?php
// Form the SQL query that returns the top 10 most populous countries
$strQuery = "SELECT count(acqid), acq_month FROM newacq GROUP BY MONTH(acq_month) ASC";
// Execute the query, or else return the error message.
$result = $conn->query($strQuery) or exit("Error code ({$conn->errno}): {$conn->error}");
$arr=mysqli_fetch_array($result);
//while($arr=mysqli_fetch_array($result)) {
// print_r($arr);
//}
// If the query returns a valid response, prepare the JSON string
if ($result) {
// The `$arrData` array holds the chart attributes and data
$arrData = array(
"chart" => array(
"caption" => "New Acq",
"showValues" => "1",
"theme" => "zune"
)
);
$arrData["data"] = array();
// Push the data into the array
while($row = mysqli_fetch_array($result)) {
array_push($arrData["data"], array(
"label" => date("M-Y", strtotime($row["acq_month"])),
"value" => $row["count(acqid)"],
)
);
}
/*JSON Encode the data to retrieve the string containing the JSON representation of the data in the array. */
$jsonEncodedData = json_encode($arrData);
/*Create an object for the column chart using the FusionCharts PHP class constructor. Syntax for the constructor is ` FusionCharts("type of chart", "unique chart id", width of the chart, height of the chart, "div id to render the chart", "data format", "data source")`. Because we are using JSON data to render the chart, the data format will be `json`. The variable `$jsonEncodeData` holds all the JSON data for the chart, and will be passed as the value for the data source parameter of the constructor.*/
$columnChart = new FusionCharts("column2D", "myFirstChart" , 820, 300, "chart-1", "json", $jsonEncodedData);
// Render the chart
$columnChart->render();
// Close the database connection
$conn->close();
}
?>
<div id="chart-1"><!-- Fusion Charts will render here--></div>
当我尝试使用 [print_r] 获取在 ARRAY 中执行的详细信息时,我收到以下消息;
Array ( [0] => 208 [count(acqid)] => 208 [1] => 2017-04-01 [acq_month] => 2017-04-01 ) Array ( [0] => 241 [count(acqid)] => 241 [1] => 2017-05-01 [acq_month] => 2017-05-01 ) Array ( [0] => 243 [count(acqid)] => 243 [1] => 2017-06-01 [acq_month] => 2017-06-01 ) Array ( [0] => 269 [count(acqid)] => 269 [1] => 2017-07-01 [acq_month] => 2017-07-01 ) Array ( [0] => 373 [count(acqid)] => 373 [1] => 2017-08-01 [acq_month] => 2017-08-01 ) Array ( [0] => 370 [count(acqid)] => 370 [1] => 2017-09-01 [acq_month] => 2017-09-01 ) Array ( [0] => 283 [count(acqid)] => 283 [1] => 2017-10-01 [acq_month] => 2017-10-01 ) Array ( [0] => 312 [count(acqid)] => 312 [1] => 2017-11-01 [acq_month] => 2017-11-01 )
它确实显示了 4 月和 11 月执行的信息,包括。如果有帮助!
【问题讨论】:
标签: php mysql arrays fusioncharts