Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Json in Flot for ploting graph?
    primarykey
    data
    text
    <p>I'm using <a href="https://github.com/flot/flot/blob/master/API.md" rel="nofollow">Flot Graph Api</a> to display bar chart, line chart in my clien side php. I try to pass Json to plot graph as they have mentioned in their examples.</p> <p>I pack the Json like this,</p> <pre><code> [{"label":"63f9311f-5d33-66ad-dcc1-353054485572","bars":{"show":true},"data": [[-170.44530493708,270.44530493708]]},{"label":"8f6dcf4a-b20c-8059-1410-353054486037","bars":{"show":true},"data":[[-791.50048402711,891.50048402711]]},{"label":"c2b4cf75-3e0b-f9ff-722e-353054485803","bars":{"show":true},"data":[[-1280.0484027106,1380.0484027106]]},{"label":"eb963e23-75cd-6131-867a-353054485894","bars":{"show":true},"data":[[-1487.2604065828,1587.2604065828]]},{"label":"ef413106-d5be-593b-1cda-353054485719","bars":{"show":true},"data":[[-1940.9583736689,2040.9583736689]]}] </code></pre> <p>But the graph is not ploting.</p> <pre><code> $.ajax({ url: '../c/By_Machine_Controller.php', //the script to call to get data data: "", //you can insert url argumnets here to pass to api.php //for example "id=5&amp;parent=6" dataType: 'json', //data format success: function(data) //on recieve of reply { var Up = []; var Down = []; Up = data[0]; //get Up Down = data[1]; //get Down //alert(Up); $.plot($("#placeholder"), [ Up , Down ]); } }); </code></pre> <p>Is it anything to do with Json or My JS is wrong. Since, i am new to flot i don't have any clue. Can anyone help me out.</p> <p>The Answer i have entered works fine, but in this case, i'm writing the JSON into a temp file and accessing it, but my requirement is,</p> <p>I calculate the values for the flot in MODEL Folder in my localhost and passing it as associative array and encoding it as a JSON in CONTROLLER Folder. Now i need to access the JSON in VIEW Folder in my localhost.</p> <p>CONTROLLER CODE:</p> <pre><code> $json = json_encode($allData); $myFile = "ReasonByTime.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Bobby Bopper\n"; fwrite($fh, $json); fclose($fh); </code></pre> <p>But when i access the $json of the CONTROLLER in the VIEW through JS like the following, its not working. I googled it but i was not able to fix it. Can you help me out with this?</p> <p>VIEW JS CODE TO ACCESS JSON From CONTROLLER.</p> <pre><code> $(document).ready(function () { //var dataurl = '../c/By_Machine_Controller.php'; function onDataReceived(data) { $.plot(placeholder, data, options); } $.ajax({ type: "GET", url: '../c/By_Machine_Controller.php', data: 'data', dataType: 'json', success: function(data) { alert(data); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload