Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a json from php to javascript for jqPlot?
    primarykey
    data
    text
    <p>Here is what I'm struggling with today:</p> <p>I'm trying to draw a graph using jqPlot library. The sql query outputs data which is converted to json in php by using <code>json_encode</code> and saved in hidden form field. This works fine and the actual field contains:</p> <pre><code>[["2011-12-10 12:01:00",271],["2011-12-10 12:13:05",132],["2011-12-11 12:17:55",388],["2011-12-10 22:03:40",5],["2011-12-11 12:10:54",830]] </code></pre> <p>Then the data from the form is retrieved in javascript by using:</p> <pre><code>var data = document.getElementById("dataarray").value; </code></pre> <p>in order to use it as a data for jqPlot later on. The <code>data</code> variable is correctly formatted and when checked with <code>document.write(data);</code>, outputs correct data in json format but whenever I place it inside the <code>plot1</code> variable to use data for the graph it throws an error <code>[object Object]</code> in Safari and <code>Uncaught #&lt;Object&gt;</code> in Firefox.</p> <p>The whole javascript code is as follows:</p> <pre><code>$(document).ready(function(){ var data = document.getElementById("dataarray").value; var test = [["2011-12-10 12:01:00",271],["2011-12-10 12:13:05",132],["2011-12-11 12:17:55",388],["2011-12-10 22:03:40",5],["2011-12-11 12:10:54",830]]; var plot1 = $.jqplot("chart_personal_2", [data], { title:"Data Point Highlighting", axes:{ xaxis:{ renderer:$.jqplot.DateAxisRenderer, numberTicks: 3, tickOptions:{ formatString:"%d/%m/%Y %H:%M:%S" } }, yaxis:{ label: "Elevation(m)", tickOptions:{ showMark: true } } }, highlighter: { show: true, sizeAdjust: 7.5 }, cursor: { show: false } }); }); </code></pre> <p>I even tried <code>output = String(data);</code> but it did not work either. I'm assuming that my <code>data</code> variable is an object that cannot be used as source data for jqPlot graph, it needs to be converted to string prior use? Correct me if I'm wrong.</p> <p>Hope somebody knows how to work it out without, thanks in advance!</p>
    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.
    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