我有一个动态创建的FLOT饼图。我通过JSON PHP MYSQL调用数据......
$.ajax({
url: 'includes/ajax/ajax-chart-client-services.php',
data: "client_id=" + $('#sel_client_id').val() + "&parent=6",
dataType: 'json',
success: function(data) {
graph_data = data;
//alert(graph_data);
var plot = $.plot('#chr_services', [graph_data], {
series: {
pie: {
show: true,
combine: {
color: '#999',
threshold: 0.1
}
}
},
legend: {
show: false
},
grid: {
hoverable: true,
clickable: true
}
});
}
});
<? //PHP PAGE HERE
$flotPieData = array();
$currentSeries = array();
while ( $row = mysqli_fetch_assoc($result) ){
$currentSeries["label"] = $row['strProductCatName'];
$currentSeries["data"] = array();
$currentSeries["data"][] = array(1,(int)$row['iqt']); //push
$flotPieData[] = $currentSeries;
}
//$flotPieData[] = $currentSeries;
echo json_encode($flotPieData);
exit();
?>
上面的PHP脚本返回以下值..
[{&#34; label&#34;:&#34; Windows Development&#34;,&#34; data&#34;:[[&#34; 1&#34;,&#34; 4&# 34;]]},{&#34;标签&#34;:&#34;手持式开发&#34;,&#34;数据&#34;:[[&#34; 1&#34;,&#34; 2&#34;]]},{&#34;标签&#34;:&#34;印刷&#34;&#34;数据&#34;:[[&#34; 1&#34;&#34 1#34;]]}]
图表没有显示任何内容。但如果我看一下数据返回它是完美的吗?
任何人都有?
答案 0 :(得分:0)
好的,我找到了解决方案。我从[graph_data]中删除[],它有效!