FLOT data from MySQL via PHP?

无人久伴 提交于 2019-12-12 02:28:37

问题


Good afternoon, I have looked at the FLOT website examples and googled but just cannot find anywhere with detailed steps on how to pull data from MySQL into FLOT.

Currently I have a php page with a recordset that stores all records from a mysql table, columns are date, user & cost. Do I need to create a data table to display all these records in the page?

When above is sorted how would I call that data into FLOT, I know its probably very obvious to any develiopers out there but I just cant find the info today.

Thanks for any help/pointers offered.


回答1:


Look the AJAX example in the flot documentation.

Essentially the steps are:

1.) Pull from database.

2.) Place data in PHP key/value array of form:

$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

$returnArray = Array($dataSet1, $dataSet2);

3.) Back in your javascript, get this json encoded string as JS variable:

var data = <?php echo json_encode($arr); ?>;

4.) Back in your javascript, call the flot plot method with that data variable:

$.plot($("#placeholder"), data, options);


来源:https://stackoverflow.com/questions/9161785/flot-data-from-mysql-via-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!