Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
JSON Results to Chart
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Skythrust" data-source="post: 475571" data-attributes="member: 87030"><p>I tried this, when I include the php file on the top of the file and I do an echo it works. When I hide the echo and try to add this in the script I will get a blanc page or the message; 'SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data'</p><p></p><p>My code;</p><p></p><p>[CODE=php]// index.php</p><p></p><p><?php include 'temp.php'; ?></p><p></p><p><!DOCTYPE html></p><p><html></p><p><script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script></p><p><body></p><p><canvas id="myChart" style="width:100%;max-width:600px"></canvas></p><p></p><p><script></p><p>const json = <?php echo $JSONAnalyse; ?></p><p></p><p>var xValues = json.map(el => el.DateTime);</p><p></p><p>new Chart("myChart", {</p><p> type: "line",</p><p> data: {</p><p> labels: xValues,</p><p> datasets: [{</p><p> data: json.map(el => el.Kh),</p><p> borderColor: "blue",</p><p> fill: false</p><p> }]</p><p> },</p><p> options: {</p><p> legend: {display: false}</p><p> }</p><p>});</p><p></script></p><p>[/CODE]</p><p>[CODE=php]// temp.php</p><p></p><p><?php</p><p>header('Content-Type: application/json; charset=utf-8');</p><p></p><p>// Aquarium Test Variables Charts</p><p>$vCalcium = "";</p><p>$vCarbonateHardness = ""; </p><p>$vIodine = "";</p><p>$vMagnesium = "";</p><p>$vNitrite = "";</p><p>$vNitrate = "";</p><p>$vAlkanity = "";</p><p>$vPhosphate = "";</p><p>$vStrontium = "";</p><p>$vSodiumChloride = "";</p><p>$vDateTime = "";</p><p></p><p>$conn=mysqli_connect(DATABASE_CONNECTION);</p><p>$sql = "SELECT * FROM Values ORDER BY DateTime DESC LIMIT 10";</p><p>$result = mysqli_query($conn, $sql);</p><p></p><p> while($row = mysqli_fetch_assoc($result))</p><p> {</p><p> $vCarbonateHardness = $row["Kh"]; </p><p> $vDateTime = $row["DateTime"]; </p><p></p><p> $AnalyseArray[] = array(</p><p> "DateTime"=> "$vDateTime", </p><p> "Kh"=> "$vCarbonateHardness"); </p><p> }</p><p> mysqli_close($conn);</p><p> $JSONAnalyse = json_encode($AnalyseArray);</p><p> //echo $JSONAnalyse;</p><p> </p><p> $conn->close();</p><p></p><p>?>[/CODE]</p><p>[automerge]1669643932[/automerge]</p><p>[USER=73182]@TheGeneral[/USER] can you please help me out with this? <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="Skythrust, post: 475571, member: 87030"] I tried this, when I include the php file on the top of the file and I do an echo it works. When I hide the echo and try to add this in the script I will get a blanc page or the message; 'SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data' My code; [CODE=php]// index.php <?php include 'temp.php'; ?> <!DOCTYPE html> <html> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> <body> <canvas id="myChart" style="width:100%;max-width:600px"></canvas> <script> const json = <?php echo $JSONAnalyse; ?> var xValues = json.map(el => el.DateTime); new Chart("myChart", { type: "line", data: { labels: xValues, datasets: [{ data: json.map(el => el.Kh), borderColor: "blue", fill: false }] }, options: { legend: {display: false} } }); </script> [/CODE] [CODE=php]// temp.php <?php header('Content-Type: application/json; charset=utf-8'); // Aquarium Test Variables Charts $vCalcium = ""; $vCarbonateHardness = ""; $vIodine = ""; $vMagnesium = ""; $vNitrite = ""; $vNitrate = ""; $vAlkanity = ""; $vPhosphate = ""; $vStrontium = ""; $vSodiumChloride = ""; $vDateTime = ""; $conn=mysqli_connect(DATABASE_CONNECTION); $sql = "SELECT * FROM Values ORDER BY DateTime DESC LIMIT 10"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)) { $vCarbonateHardness = $row["Kh"]; $vDateTime = $row["DateTime"]; $AnalyseArray[] = array( "DateTime"=> "$vDateTime", "Kh"=> "$vCarbonateHardness"); } mysqli_close($conn); $JSONAnalyse = json_encode($AnalyseArray); //echo $JSONAnalyse; $conn->close(); ?>[/CODE] [automerge]1669643932[/automerge] [USER=73182]@TheGeneral[/USER] can you please help me out with this? :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
JSON Results to Chart
Top