Home Forums Chart Support Displaying incorrect date time while converting epoch value

Displaying incorrect date time while converting epoch value

Viewing 2 posts - 1 through 2 (of 2 total)
  • #25294

    In xaxis i need to display the date time, as i am passing the epoch value, but it is displaying the old date of 1970.

    but if i am converting the epoch value to date time then it shows the exact value.

    >>> time.strftime(‘%Y-%m-%d %H:%M:%S’, time.localtime(1558743070))
    ‘2019-05-25 05:41:10’

    Where i am going wrong. Please help me.

    Below is my code:
    ————————-

    window.onload = function () {

    var chart = new CanvasJS.Chart(“chartContainer”,
    {
    axisY:{
    valueFormatString:”$#######.00″
    },
    axisX:{

    xValueType: “dateTime”,
    valueFormatString: “DD/MM/YYYY HH:mm”
    },
    data: [
    {
    type: “spline”,
    xValueType: “dateTime”,
    xValueFormatString:”DD/MM/YYYY HH:mm”,
    yValueFormatString:”$#######.00″,
    dataPoints: [
    {‘x’:1558743070,’y’:566},{‘x’:1558743130,’y’:563},{‘x’:1558743190,’y’:565},{‘x’:1558743250,’y’:564},{‘x’:1558743310,’y’:566},{‘x’:1558743370,’y’:569},{‘x’:1558743430,’y’:570},{‘x’:1558743490,’y’:565},{‘x’:1558743550,’y’:566},{‘x’:1558743610,’y’:565},{‘x’:1558743670,’y’:568},{‘x’:1558743730,’y’:569},{‘x’:1558743790,’y’:565},{‘x’:1558743850,’y’:567},{‘x’:1558743910,’y’:570},{‘x’:1558743970,’y’:571},{‘x’:1558744030,’y’:568},{‘x’:1558744090,’y’:569}
    ]
    }
    ]
    });

    chart.render();
    }

    #25306

    @akarsh5080,

    Epoch timestamp is in seconds whereas JavaScript uses milliseconds as timestamp. Converting epoch timestamp to JavaScript timestamp before passing it to chart should work fine in your case. You can convert epoch timestamp to JavaScript timestmap by multiplying epoch timestamp by 1000. $javaScriptTimestamp = $epochTimestamp * 1000; Please refer this stackoverflow thread for more information on the same.


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.