I'm trying to draw multiple series into flotchart. I'm successfully getting 1 label, but I'm stuck to get more labels with PHP and encode to json.
$connection = mysql_connect($server,$user,$password);
$db = mysql_select_db($database,$connection);
$query = "SELECT SC,SR FROM high";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$int = $row['SR'];
$join = intval($int);
$int2 = $row['SC'];
$join2 = intval($int2);
$dataset1[] = array($join2,$join);
}
$final = json_encode($dataset1);
echo $final;
RESULT
[[1,3],[2,20],[3,30],[4,10],[5,4],[6,40],[7,67],[8,100],[9,5],[10,11]]
Parse JSON to Javascript
$.ajax({
dataType:'json', /*to avoid calling JSON.parse(data) in your callback function*/
url: 'chart-data.php',
success: function (data) {
console.log(data);//as mentioned in comments
//1.either call plot again
/*calling plot as seen in your code - start*/
var d1 = data;/* JSON.parse(data) */
$.plot($("#placeholder"),
[{
label: "SCR",
data: d1,
},
/*{
label: "SCR",
data: d1,
},*/
],
FOKUS ON {label: "SCR",data: d1,},
Question: How to parse JSON data to JS like :
[ { label: "Foo", data: [ [10, 1], [17, -14], [30, 5] ] },
{ label: "Bar", data: [ [11, 13], [19, 11], [30, -7] ] }
]
I'm just trying to use array:
$s= array('label'=> "aaaa",
'data'=> $final);
print_r($s);
and get result
Array ( [label] => aaaa [data] => [[1,3],[2,20],[3,30],[4,10],[5,4],[6,40],[7,67],[8,100],[9,5],[10,11]] )