Home forums Using CanvasJS Convert to date format

This topic contains 4 replies, has 2 voices, and was last updated by  Indranil Deo 1 week, 2 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #20268

    I am getting JSON data from a python script (for drawing candlestick chart) in following format.
    [{"y": [10714.7, 10717.95, 10714.3, 10717.5], "x": "2018/01/16 14:26:00"}, {"y": [10718.0, 10718.0, 10713.45, 10716.2], "x": "2018/01/16 14:27:00"}, {"y": [10716.6, 10722.0, 10716.1, 10719.15], "x": "2018/01/16 14:28:00"}]

    The date/time is in string format.
    (There are thousands of records, I have indicated a few.)

    Now the help requested is, how do I convert the date/time in correct format for the entire data by replacing old values in-place.
    Thanks.

    • This topic was modified 1 week, 3 days ago by  Vineet Deodhar. Reason: added info
    #20270

    I gave it a try.

    var rawData = [
    		{"y": [10714.7, 10717.95, 10714.3, 10717.5], "x": "2018/01/16 14:26:00"},
    		{"y": [10718.0, 10718.0, 10713.45, 10716.2], "x": "2018/01/16 14:27:00"},
    		{"y": [10716.6, 10722.0, 10716.1, 10719.15], "x": "2018/01/16 14:28:00"}
    		]
    for (i = 0; i < 3; i++){rawData[i]["x"]=new Date(rawData[i]["x"]);}

    Mostly, it is ok.
    But the it gives Date, not DateTime.

    I tried new Date(rawData[i]["x"]).format("isoDateTime")
    But error.

    What I maybe missing?
    Thanks.

    #20271

    Now, almost done.
    I have set valueFormatString: "DD-MMM-YYYY HH-mm", for axisX.

    1) If there are a few records,date time are displayed twice on x-axis.
    2) As the no. of records increases in the same day, X-axis labels are not displayed for in-between records. Displayed after every 10 records.
    3) If there is data for different dates, obviously there is no data during off-market hours. But X-axis space is reserved for these empty slots. You can view it in the jsfiddle below.
    What should be corrected?
    This jsfiddle shows the result.

    Thanks.

    #20273

    Since EDIT is disabled in above post, creating a new reply.
    multiple dates jsfiddle can be viewed here.

    #20281

    Indranil Deo
    Member

    @d_vineet,

    Setting the interval and intervalType for axisX should work fine in your case.

    ___________
    Indranil Deo,
    Team CanvasJS

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

You must be logged in to reply to this topic.