Home forums Chart Support MySQL – (Displaying Date-Time values on a Chart Axis)

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #21954

    So I’m looking to do what’s achieved here but my data is from a MySQL Database. But I need to count the total times that date is listed automatically instead of manually.
    For example;
    In my database, I have the following dates,
    2016-08-30 ~ 2016-10-23 ~ 2016-10-23 ~ 2017-02-12 ~ 2018-08-30 ~ 2018-08-30 ~ 2017-02-12
    and in my graph, I want the,
    X = date
    Y = amount that date is listed in DataBase
    so the result should look like this,
    X = 2016-08-30 ~ 2016-10-23 ~ 2017-02-12 ~ 2018-08-30
    y = 1 ~ 2 ~ 2 ~ 2

    I hope this all made sense :)

    Thanks in advance.



    Here is an example with the similar scenario. This example reads data from an array instead of database.

    Priyanka M S
    Team CanvasJS


    Yea that’s awesome, quick question? I’m using a JSON file to get the dates, how can I incorporate that into that example?



    Please take a look into this jsfiddle, here the data is served from an external JSON source.

    Priyanka M S
    Team CanvasJS


    Thanks that’s perfect, quick of topic question how did you code your JSON? Your’s looks much better then mine :) http://banlister.com/graph-test/service.php



    The JSON data we have provided is an array of objects. In your case, it’s an array of arrays.

    Priyanka M S
    Team CanvasJS


    Ah ok. So my JSON should still work much like yours or do I need to change to be an array of objects (if so how would I do that? I’m not that familiar with JSON files in case you can’t tell) Thanks so much for Helping Priyanka :)



    When you use JSON data as an array of arrays, you need to slightly modify the above fiddle.
    Please take a look at this updated jsfiddle.

    Priyanka M S
    Team CanvasJS


    I’m not sure what I’m doing wrong, but I have a feeling it’s my JSON code… Here is a jsfiddle using my JSON and here is the code behind my JSON

    $username = "";
    $password = "";
    $dbname = "";
    // Create connection
    $conn = new mysqli('localhost',$username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    $sql = "SELECT date FROM db";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        // output data of each row
    	$obj = array();
        while($row = $result->fetch_assoc()) {
    		$element = array($row["ban_date"]);
    	echo json_encode($obj);
    } else {
        echo "0 results";
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.