I need to create chart using Flot chart library, using PHP JSON functions (ie. json_encode).
Problem is that I don’t understand structure of PHP array that have to be encoded to create proper JS array for generating Flot charts.
Chart needs to have several lines, with different colors.
Can somebody help me with some example of proper PHP array for this kind.
I have tried (without success) to implement next example:
Problem with it is that I’m getting Object that I don’t know how to implement in my script:
$.ajax({
type:'post',
dataType: "json",
url:'/stocks/index/',
success: function(r) {
$.plot($("#placeholder"), [
{data:(r)}
] )
}
});
Thank you in advance!
UPDATE: php code used to generate JSON array looks like this:
$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 file..
and