[我使用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>
上面,图表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]
的结果。但是在chart-mon
中没有显示任何数据。但是我运行selectchart.php
selectchart.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: