unix 时间戳在 amcharts 中无法显示图表
unix timestamp doesn't work in amcharts for showing chart
我正在使用 unix 时间戳作为图表的类别字段,但它不起作用。这是我的 json 数据的示例:
{
"id": 1546387200,
"upload_id": 1,
"bg": 23
}
id 是一个 unix 时间戳,我将此字段用作图表的类别字段:
"categoryField": "id",
"categoryAxis": {
"dashLength": 1,
"minorGridEnabled": true,
"labelsEnabled": true,
"tickLength": 0
},
为什么这不起作用?
首先我建议切换到 amcharts4,因为它更灵活,甚至有新的图表类型。您可以轻松迁移,从一个图表开始。您可以并行使用 amcharts3 和 amcharts4 (Migration Guide)。
要解决您的问题,您应该为您的 categoryAxis 设置 parseDates
属性 并将其设置为 true
(docs).
"categoryAxis": {
"dashLength": 1,
"minorGridEnabled": true,
"labelsEnabled": true,
"tickLength": 0,
"parseDates": true
},
我创建了 this code pen 作为参考。希望对您有所帮助。
我正在使用 unix 时间戳作为图表的类别字段,但它不起作用。这是我的 json 数据的示例:
{
"id": 1546387200,
"upload_id": 1,
"bg": 23
}
id 是一个 unix 时间戳,我将此字段用作图表的类别字段:
"categoryField": "id",
"categoryAxis": {
"dashLength": 1,
"minorGridEnabled": true,
"labelsEnabled": true,
"tickLength": 0
},
为什么这不起作用?
首先我建议切换到 amcharts4,因为它更灵活,甚至有新的图表类型。您可以轻松迁移,从一个图表开始。您可以并行使用 amcharts3 和 amcharts4 (Migration Guide)。
要解决您的问题,您应该为您的 categoryAxis 设置 parseDates
属性 并将其设置为 true
(docs).
"categoryAxis": {
"dashLength": 1,
"minorGridEnabled": true,
"labelsEnabled": true,
"tickLength": 0,
"parseDates": true
},
我创建了 this code pen 作为参考。希望对您有所帮助。