javascript - Fusioncharts中没有数据显示错误
问题描述
我使用 ajax 渲染图表。我有两个文件 index.php ,selectchart.php。在 index.php 中,我使用 ajax 渲染图表。
<div class="chart-area">
<div id="chart-1"><!-- Fusion Charts will render here--></div>
<div id="chart-mon"><!-- Fusion Charts will render here--></div>
上图,chart-1 div 用于年报,然后我们选择月份,图表将根据选择显示。
</div>
<p><select class="btn btn-light btn-icon-split" id="country" name="country">
<option>--Select Month--</option>
<option value="01">JAN</option>
<option value="02">FEB</option>
<option value="03">MAR</option>
<option value="04">APR</option>
<option value="05">MAY</option>
<option value="06">JUN</option>
<option value="07">JUL</option>
<option value="08">AUG</option>
<option value="09">SEP</option>
<option value="10">OCT</option>
<option value="11">NOV</option>
<option value="12">DEC</option>
</select></p>
Javascript
<script type="text/javascript">
$('#country').change(function() {
var selectedcountry = $(this).children("option:selected").val();
//alert(selectedcountry);
$.ajax({
type : "POST",
url : "selectchart.php?country="+selectedcountry,
data : selectedcountry,
success: function(result)
{
$("#chart-1").hide();
//$("#myDiv").show();
alert(result);
var myChart = new FusionCharts("column2D", "myThird", 400, 300, "json", result);
myChart.render("chart-mon");
}
});
});
</script>
我已经提醒结果显示了。但是没有显示任何数据。但是我运行了[objectoject]
selectchart.phpchart-mon
选择图表.php
include("includes/fusioncharts.php");
$selectdata = $_REQUEST['country'];
$dbhandle = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
if ($dbhandle->connect_error) {
exit("There was an error with your connection: ".$dbhandle->connect_error);
}
$strQuerymon = "SELECT name, amount FROM income WHERE month = '$selectdata'ORDER BY amount DESC LIMIT 10";
$resultmon = $dbhandle->query($strQuerymon) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
if ($resultmon) {
$arrDatamon = array(
"chart" => array(
"showValues" => "0",
"theme" => "zune"
)
);
$arrDatamon["data"] = array();
while($rowmon = mysqli_fetch_array($resultmon)) {
array_push($arrDatamon["data"], array(
"label" => $rowmon["name"],
"value" => $rowmon["amount"]
)
);
}
$jsonEncodedDatamon = json_encode($arrDatamon);
echo $jsonEncodedDatamon;
header('Content-type: text/json');
}
{"chart":{"showValues":"0","theme":"zune"},"data":[{"label":"washing","value":"1000"},{"label":"cleanin","value":"444"},{"label":"rwr","value":"333"},{"label":"sample","value":"300"},{"label":"werew","value":"33"},{"label":"demo","value":"10"}]} these values are displayed.[enter image description here][1]
解决方案
解决方案1:
我认为你传递错了:
取而代之的是
var myChart = new FusionCharts("column2D", "myChartId" , 400, 300, "json", "result");
你必须通过:
var myChart = new FusionCharts("column2D", "myChartId" , 400, 300, "json", result );
因为结果(它是变量)是来自您的 selectchart.php 页面的响应。