|
|
1
xorspark
6 年前
如注释中所述,AmCharts需要一个对象数组。您拥有的是一个具有(外观无效)键值条目的单个对象。
您希望您的有效JSON响应如下所示:
[{
"date": "2018-04-28 17:03:04",
"value": 9.2090000000,
}, {
"date": "2018-04-28 18:03:15",
"value": 9.1870000000
},
// etc
]
你的
valueField
和
categoryField
属性需要设置为与数据中的这些键相对应的字符串,例如。
graphs: [{
// ...
valueField: "value"
}],
categoryField: "date"
由于您使用的是基于日期的数据,您可能还需要考虑设置
parseDates
至true和a
dataDateFormat
这样它就可以正确地解析日期和管理时段。您还需要设置
minPeriod
对应于各点之间的最小可能间隔(
"hh"
持续数小时或
"mm"
在这种情况下,只需几分钟):
categoryAxis: {
parseDates: true,
minPeriod: "mm",
// ...
},
dataDateFormat: "YYYY-MM-DD JJ:NN:SS",
这是一个有效的演示:
var data = [{
"date": "2018-04-28 17:03:04",
"value": "9.2090000000"
}, {
"date": "2018-04-28 18:03:15",
"value": "9.1870000000"
}, {
"date": "2018-04-28 19:06:43",
"value": "9.1870000000"
}, {
"date": "2018-04-28 20:07:41",
"value": "9.1880000000"
}, {
"date": "2018-04-28 21:08:16",
"value": "9.1810000000"
}, {
"date": "2018-04-28 22:08:29",
"value": "9.1840000000"
}, {
"date": "2018-04-28 23:08:30",
"value": "9.1870000000"
}, {
"date": "2018-04-29 00:10:12",
"value": "9.2380000000"
}, {
"date": "2018-04-29 01:10:39",
"value": "9.3180000000"
}, {
"date": "2018-04-29 02:10:57",
"value": "9.5170000000"
}, {
"date": "2018-04-29 03:11:56",
"value": "9.4510000000"
}, {
"date": "2018-04-29 04:13:41",
"value": "9.4490000000"
}, {
"date": "2018-04-29 05:13:43",
"value": "9.4520000000"
}, {
"date": "2018-04-29 06:15:47",
"value": "9.3810000000"
}, {
"date": "2018-04-29 07:16:46",
"value": "9.4440000000"
}, {
"date": "2018-04-29 08:17:47",
"value": "9.4100000000"
}, {
"date": "2018-04-29 09:18:31",
"value": "9.2130000000"
}, {
"date": "2018-04-29 10:19:47",
"value": "9.2680000000"
}, {
"date": "2018-04-29 11:21:00",
"value": "9.2810000000"
}, {
"date": "2018-04-29 12:22:08",
"value": "9.3430000000"
}, {
"date": "2018-04-29 13:23:47",
"value": "9.3270000000"
}, {
"date": "2018-04-29 14:23:51",
"value": "9.3680000000"
}, {
"date": "2018-04-29 15:24:13",
"value": "9.3770000000"
}, {
"date": "2018-04-29 16:25:53",
"value": "9.4210000000"
}];
AmCharts.makeChart("chartdiv", {
"type": "serial",
"dataProvider": data,
"categoryField": "date",
"autoMargins": false,
"marginLeft": 0,
"marginRight": 5,
"marginTop": 0,
"marginBottom": 0,
"graphs": [{
"valueField": "value",
"showBalloon": false,
"lineColor": "#ffbf63",
"negativeLineColor": "#289eaf"
}],
"valueAxes": [{
"gridAlpha": 0,
"axisAlpha": 0,
"guides": [{
"value": 0,
"lineAlpha": 0.1
}]
}],
"dataDateFormat": "YYYY-MM-DD JJ:NN:SS",
"categoryAxis": {
"gridAlpha": 0,
"parseDates": true,
"minPeriod": "mm",
"axisAlpha": 0,
"startOnAxis": true
}
});
#chartdiv {
width: 100px;
height: 100px;
}
<script type="text/javascript" src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script type="text/javascript" src="https://www.amcharts.com/lib/3/serial.js"></script>
<div id="chartdiv"></div>
|