创建Flot图表所需的PHP数组结构(带有JSON)
我需要使用Flot图表库,使用PHP JSON函数(即JSON_encode)创建图表 问题是,我不理解PHP数组的结构,为了生成Flot图表,必须对其进行编码以创建适当的JS数组 图表需要有几行不同颜色的线 有人能帮我举一些适合这种类型的PHP数组的例子吗 我已尝试(未成功)实施下一个示例: 问题是我得到了一个我不知道如何在脚本中实现的对象:创建Flot图表所需的PHP数组结构(带有JSON),php,json,flot,Php,Json,Flot,我需要使用Flot图表库,使用PHP JSON函数(即JSON_encode)创建图表 问题是,我不理解PHP数组的结构,为了生成Flot图表,必须对其进行编码以创建适当的JS数组 图表需要有几行不同颜色的线 有人能帮我举一些适合这种类型的PHP数组的例子吗 我已尝试(未成功)实施下一个示例: 问题是我得到了一个我不知道如何在脚本中实现的对象: $.ajax({ type:'post', dataType: "json", url:'
$.ajax({
type:'post',
dataType: "json",
url:'/stocks/index/',
success: function(r) {
$.plot($("#placeholder"), [
{data:(r)}
] )
}
});
提前谢谢你
更新:用于生成JSON数组的php代码如下所示:
$dataSet1 = array();
$dataSet1['label'] = 'Customer 1';
$dataSet1['data'] = array(array(1,1),array(2,2)); // an array of arrays of point pairs
$dataSet2 = array();
$dataSet2['label'] = 'Customer 2';
$dataSet2['data'] = array(array(3,3),array(4,5)); // an array of arrays of point pairs
$flots = array($dataSet1, $dataSet2);
return json_encode($flots);
php文件
及
也显示你的PHP代码。。另外,json的响应是一个javascript对象,因此[{}]不需要:)它在我的消息Dont return json_encode的更新部分。。附和它;)我以前试过,运气不好。
$dataSet1 = array();
$dataSet1['label'] = 'Customer 1';
$dataSet1['data'] = array(array(1,1),array(2,2)); // an array of arrays of point pairs
$dataSet2 = array();
$dataSet2['label'] = 'Customer 2';
$dataSet2['data'] = array(array(3,3),array(4,5)); // an array of arrays of point pairs
$flots = array($dataSet1, $dataSet2);
echo json_encode($flots);
$.ajax({
type:'post',
dataType: "json",
url:'/stocks/index/',
success: function(data) {
$.plot($("#placeholder"), data );
}
});