Home forums Using CanvasJS Displaying incorrect date time while converting epoch value

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Vishwas R 4 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #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 JS timestamp before passing it to chart, by multiplying epoch timestamp by 1000 should work fine in your case. Please refer this stackoverflow thread for more information.


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.