You must be logged in to post your query.
Home › Forums › Chart Support › How to print just the date when importing dateTime from PHP
Tagged: php
Hi there,
I am currently creating a page where you can view statistics from a game I made. I am importing date from a MySQL database with the a DateTime row. Now I want to display just the month and day on my x-axis, instead of year, month, day, and the exact time. I know there is a documentation, but I couldn’t find a working solution over there.
I currently have this as the PHP:
//Maak verbinding met server $servername = ".."; $username = ".."; $password = ".."; $dbname = ".."; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM geometry_results WHERE " . $_SESSION['userID'] . " = userID ORDER BY datum asc"; $result = $conn->query($sql); $dataPoints = array(); if ($result->num_rows > 0) { // output data of each row while ($row = $result->fetch_assoc()) { $results = $row['goed']; $mes = date(2000, 10, 10); // $text = 'Time: ' . $row['time']; array_push($dataPoints, array("y" => ($row['tijd'] / 10), "label" => date($row['datum']), "wins" => $row['goed'], "false" => $row['fout'])); // array_push($dataPoints, array('y' => Date(2012, 02, 02), "label" => $row['datum'])); } } else { $results = "0 results"; } $conn->close();
And this as a script to load the statistics in a line diagram: https://hastebin.com/ekidupukuq.js
@timyboy12345,
In the code snippet that you have shared, the date-time values being read from database are assigned as labels instead of assigning it as x values. Hence, setting the valueFormatString won’t work in this case. Instead, you can go with one of the following options:
1) Format the date before assigning it to the label, or 2) Pass it as date-time and assign it to x value. And format it using valueFormatString.
___________ Indranil Deo, Team CanvasJS
You must be logged in to reply to this topic. Login/Register