我正在Angular 8.0.1上使用amChart 4。问题在于它会自动对数据进行分组,并给出代表当天范围的垂直线,而不是绘制每个点并显示趋势。后者是我所期望的。
我已注释所有其他设置,仅保留基本代码:
ngAfterViewInit() {
this.ngZone.runOutsideAngular(() => {
this.chart = am4core.create(this.chartElement.nativeElement, XYChart);
const dateAxis = this.chart.xAxes.push(new DateAxis());
const valueAxis = this.chart.yAxes.push(new ValueAxis());
const series = this.chart.series.push(new LineSeries());
series.dataFields.dateX = this.dateField; // dateField = 'DATE_TIME'
series.dataFields.valueY = this.valueField; // valueField = 'ALL'
if (this.pending && this.pending.length) {
this.chart.data = pending;
this.pending = [];
}
});
}
ngOnInit() {
this.data$.subscribe(data => {
if (this.chart) {
this.chart.data = data;
} else {
this.pending = data;
}
});
}
虽然我的数据是一个约有15K点的数组,格式如下:
[
{
"DATE_TIME": "2020-03-13T07:04:34.410Z",
"ALL": 4335
},
{
"DATE_TIME": "2020-03-13T07:05:46.900Z",
"ALL": 4332
},
{
"DATE_TIME": "2020-03-13T07:06:58.720Z",
"ALL": 4344
},
// ...
{
"DATE_TIME": "2020-03-25T17:53:08.720Z",
"ALL": 5606.59
},
{
"DATE_TIME": "2020-03-25T17:54:20.870Z",
"ALL": 5575.9400000000005
}
]
我想是因为数据太大,所以amCharts会自动按日期对数据进行分组。但是无论如何,我可以取消此默认设置吗?
对于基于日期的图表,AmCharts假定使用每日数据(yyyy-MM-dd
),这说明了为什么图表看起来是这样。由于您的数据具有随附的时间戳(ISO8601),因此您需要修改inputDateFormat
以告知图表还解析出时间分量。 AmCharts提供了一种特殊的inputDateFormat
格式代码来自动解析ISO日期:
i
您可以找到更多格式代码chart.dateFormatter.inputDateFormat = 'i';
您还希望在日期轴上指定一个here以匹配日期数据的粒度,以便图表可以正确绘制序列和轴。
baseInterval