在脚本中我有以下代码:
<script>
var pie_chart = AmCharts.makeChart("chartpie",{
"type" : "pie",
"depth3D": 15,
"theme": "light",
"titleField" : "category",
"valueField" : "column-1",
"angle":30,
"minRadius" : 50,
"labelText": "[[percents]]%",
"dataLoader": {
"url": "loadPie.php",
"format": "json"
}
});
</script>
在loadPie.php
中,我有以下代码:
<?php
// Set proper HTTP response headers
header( 'Content-Type: application/json' );
$link = mysqli_connect('localhost', 'pharmana_general', '123456pharmana', 'pharmana_Hareket_db');
mysqli_set_charset($link , "utf8"); /* Procedural approach */
$query = " SELECT SUM(KDV) AS TotalKDV,Ana_Kategori
FROM general_Table
GROUP BY Ana_Kategori";
$result = $link->query( $query );
// Print out rows
$data = array();
while ( $row = $result->fetch_assoc() ) {
$data[] = $row;
}
echo json_encode( $data );
?>
这应该有用,但它不会,它只显示空白区域。关于如何解决这个问题的任何建议?
(我在html中包含了这段代码:
<script src="http://www.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js" type="text/javascript"></script> )
答案 0 :(得分:1)
您需要确保PHP脚本返回的数据中的字段与图表中的titleField
和valueField
匹配,以便DataLoader插件可以使用饼图。您的PHP脚本似乎返回了包含TotalKDV
和Ana_Kategori
的行数组,但您的valueField
和titleField
设置为"column-1"
和"category"
}, 分别。假设您的数据如下所示:
[{
"Ana_Kategory": "Category 1",
"TotalKDV": 10
},{
"Ana_Kategory": "Category 2",
"TotalKDV": 20
}]
您的valueField
必须为"TotalKDV"
且titleField
必须为"Ana_Kategori"
:
var pie_chart = AmCharts.makeChart("chartpie",{
"type" : "pie",
"depth3D": 15,
"theme": "light",
"titleField" : "Ana_Kategori",
"valueField" : "TotalKDV",
"angle":30,
"minRadius" : 50,
"labelText": "[[percents]]%",
"dataLoader": {
"url": "loadPie.php",
"format": "json"
}
});