Search code examples
javascriptamcharts

unix timestamp doesn't work in amcharts for showing chart


I'm using a unix timestamp as a category field of my chart but it doesn't work. Here is a sample of my json data:

{
    "id": 1546387200,
    "upload_id": 1,
    "bg": 23
}

The id is a unix timestamp and I'm using this field as a category field of my chart:

"categoryField": "id",
"categoryAxis": {
    "dashLength": 1,
    "minorGridEnabled": true,
    "labelsEnabled": true,
    "tickLength": 0
},

Why isn't this working?


Solution

  • First of all I recommend switching to amcharts4, because it is much more flexible and has even new chart types. You can migrate easily, beginning with just one chart. You can use amcharts3 and amcharts4 in parallel (Migration Guide).

    To solve your problem you should set the parseDates property for your categoryAxis and set it to true (docs).

    "categoryAxis": {
        "dashLength": 1,
        "minorGridEnabled": true,
        "labelsEnabled": true,
        "tickLength": 0,
        "parseDates": true
    },
    

    I created this code pen as reference. Hope that helps.