如何在jqplot图表中使用php值(由ajax发送)?
下面粘贴的代码不会创建图表。当我手动键入值数组时,图形将会绘制图表。我将图表发送到ID为“chart1”的div。
--- PHP ---
$array = array(
array("Books", 12),
array("Movies", 9)
);
$json = json_encode($array);
var_dump($json);
---- JAVASCRIPT ----
$(document).ready(function(){
var charts;
$.ajax({
type: "POST",
async: false,
dataType: "json",
url: "submitform.php",
data: 'action=chart',
success: function(data){
charts = data;
}
});
var plot1 = jQuery.jqplot ('chart1', [charts],
{
seriesDefaults: {
shadow: false,
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
highlightMouseOver: false,
showDataLabels: true
}
},
seriesColors: [ "#CCF", "#FCC", "#6CF", "#6C6", "#FF9"],
legend: { show:true, location: 'e' }
}
);
});
如果我提醒(图表)我明白了:
[["Books",12],["Movies",9]]
所以我认为我的格式很好。
哎呀,抱歉,如果那么久。 (抱歉格式不佳)答案 0 :(得分:0)
试试吧
$(document).ready(function(){
$(".success").fadeIn("fast");
var charts = null;
$.ajax({
type: "POST",
async: false,
url: "submitform.php",
data: 'action=chart',
dataType: "json",
success: function(data){
charts = data;
$(".success").html(charts + "charts ");
}
});
var chartData = [["Books",12], ["Movies",9]];
alert(charts);
var plot1 = jQuery.jqplot ('chart1', [charts], {
seriesDefaults: {
shadow: false,
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
highlightMouseOver: false,
showDataLabels: true
}
},
seriesColors: [ "#CCF", "#FCC", "#6CF", "#6C6", "#FF9"],
legend: { show:true, location: 'e' }
});
});