Home forums Using CanvasJS Date using PHP

This topic contains 1 reply, has 2 voices, and was last updated by  Priyanka M S 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23046

    I’m using PHP to dynamically display a value for each date/day of the week.

    The format request from mysql db is YYYY-MM-DD.

    How do I convert that so CanvasJS will read it correct? I see samples like the following which makes zero sense on conversion.

    data: [
    {
    type: “area”,
    dataPoints: [//array
    { x: new Date(2012, 01, 1), y: 26},
    { x: new Date(2012, 01, 3), y: 38},
    { x: new Date(2012, 01, 5), y: 43},
    { x: new Date(2012, 01, 7), y: 29},
    { x: new Date(2012, 01, 11), y: 41},
    { x: new Date(2012, 01, 13), y: 54},
    { x: new Date(2012, 01, 20), y: 66},
    { x: new Date(2012, 01, 21), y: 60},
    { x: new Date(2012, 01, 25), y: 53},
    { x: new Date(2012, 01, 27), y: 60}

    #23054

    Priyanka M S
    Member

    @don-leesuccessrocket-io,

    To convert PHP date to JavaScript timestamp, first, you need to convert PHP date to PHP timestamp using strtotime and then convert PHP timestamp to JavaScript timestamp by multiplying PHP timestamp by 1000. Also, setting xValueType to ‘dateTime’ should work fine in your case.

    $phpDate = date("Y-m-d h:i:sa");
    $phpTimestamp = strtotime($phpDate);
    $javaScriptTimestamp = $phpTimestamp * 1000;

    If this doesn’t solve your requirement, kindly share a sample project along with sample database over Google Drive or Onedrive reproducing the issue your are facing, so that we can look into your code, understand it better and help you out.

    __
    Priyanka M S
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.