Lukas
Lukas

Reputation: 11

Amcharts can't correctly parse datetime from mysql

I have this JSON data (chartData):

[{"date":"2017-01-24 12:00:00","op":"678.283"},{"date":"2017-01-24
13:00:00","op":"616.854"},{"date":"2017-01-24 14:00:00","op":"611.969"},{"date":"2017-01-24 15:00:00","op":"602.912"},...

and display it by following code:

AmCharts.makeChart( "chartdiv", {
"type": "serial",
"dataProvider": chartData,
"categoryField": "date",
"dataDateFormat": "YYYY-MM-DD JJ:NN:SS",
"categoryAxis": {
    "parseDates": true,
    "labelRotation": 60,               
},
"graphs": [ {
"valueField": "op"              
} ]
} );

I created format accorging to https://www.amcharts.com/kbase/formatting-dates/. The chart correctly parses days, but can't separate items in one day, so they are displayed as one vertical line, see resulting plot Can anybody help?

Upvotes: 0

Views: 789

Answers (1)

xorspark
xorspark

Reputation: 16012

You need to set a minPeriod that represents the minimum time interval between each of your points. The default minPeriod is daily ("DD") so you'll want to adjust that for your data, which appears to be hourly ("hh") from your sample data.

AmCharts.makeChart( "chartdiv", {
  // ..
  "categoryAxis": {
    "parseDates": true,
    "minPeriod": "hh",
    "labelRotation": 60         
  },
  // ..
} );

Demo

Upvotes: 1

Related Questions