数据未在AMCharts中正确显示(使用dataLoader检索的数据)

时间:2019-02-25 09:36:51

标签: javascript json amcharts

我正在将带有数据的json文件加载到我的图表中,并且我将日期时间显示为类别轴。似乎做错了,因为它表明存在1899年的数据,而json文件中最旧的数据来自2018年。我使用dateParser对其进行了正确的日期结构解析,但是当我不对其进行解析时,它正确显示在图表中,但随后我无法在数据上使用时间函数。因此,这是一个大问题。以下是我的图表代码:

var chartConfig = {
    "dataLoader": {
        "url": "datafiles/dummyData.json",
        "format": "json",
                "showErrors": true,
        "noStyles": true,
        "async": true
    },
    "type": "serial",
    "theme": "none",
    "marginLeft": 70,
    "dataDateFormat": "D/MM/YYYY J:NN",
    "graphs": [{
        "bullet": "round",
        "bulletBorderAlpha": 1,
        "bulletColor": "#FFFFFF",
        "bulletSize": 5,
        "hideBulletsCount": 50,
        "lineThickness": 2,
        "lineColor": "#000000",
        "title": "red line",
        "useLineColorForBulletBorder": true,
        "valueField": "Historie glucose (mg/dL)"
  }],
    "chartCursor": {
        "categoryBalloonEnabled": false
    },
    "categoryField": "Tijd",
    "categoryAxis": {
        "parseDates" : true,
        "minPeriod" : "hh",
        "dashLength": 1,
        "minorGridEnabled": true,
        "labelsEnabled": true,
        "tickLength": 0
    },
    "valueAxes": [{
        "ignoreAxisWidth": true
  }],
    guides: [{
        //value axis guide
        value: 100,
        toValue: 200,
        fillAlpha: .40,
        fillColor: "#008000"
}, {
        value: 0,
        toValue: 100,
        fillAlpha: 0.40,
        fillColor: "#0000FF"
}, {
        value: 200,
        toValue: 10000,
        fillAlpha: 0.40,
        fillColor: "#FF0000"
}]
};

这是我的json文件的示例:

  {
     "ID":75461
    ,"Tijd":"6/11/2018 5:47"
    ,"Type vastlegging":0
    ,"Historie glucose (mg/dL)":122
    ,"Scan glucose (mg/dL)":null
    ,"Niet-numeriek snelwerkende insuline":""
    ,"Snelwerkende insuline (eenheden)":""
    ,"Niet-numeriek voedsel":""
    ,"Koolhydraten (gram)":""
    ,"Niet-numeriek langwerkende insuline":""
    ,"Langwerkende insuline (eenheden)":""
    ,"Notities":""
    ,"Strip glucose (mg/dL)":""
    ,"Keton (mmol/L)":""
    ,"Maaltijdinsuline (eenheden)":""
    ,"Correctieinsuline (eenheden)":""
    ,"Gebruikerswijziging insuline (eenheden)":""
    ,"Vorige tijd":""
    ,"Bijgewerkte tijd":""
  }

以下是数据在图表中的显示方式的屏幕截图:

Chart with wrong data

有人可以帮我吗?我一直在找几天。预先感谢!

1 个答案:

答案 0 :(得分:1)

该问题可能是由于您的时间戳格式所致。如this article中所述,dataDateFormat不支持用星号标记的单字母格式代码(尤其不允许DJ-您需要{{1} }和DD)。您需要将小时和天数零填充到数据中,并相应地调整JJ