我从chartService
收到了这样的json,但是当我尝试显示数据时,每个日期都会添加1天。我正在使用Genymotion进行仿真。我不知道这是否可能是内部模拟器时区问题,有人会知道发生了什么吗?
JSON = [{
"fecha": "2019-09-23",
"km_rec": 431.56
}, {
"fecha": "2019-09-25",
"km_rec": 187.12
}, {
"fecha": "2019-09-26",
"km_rec": 270.08
}, {
"fecha": "2019-09-27",
"km_rec": 121.04
}, {
"fecha": "2019-09-28",
"km_rec": 407.96
}, {
"fecha": "2019-09-29",
"km_rec": 10.98
}]
<StackLayout class="c-stacklayout" alignItems="flex-end">
<GridLayout class="modal_chart">
<RadCartesianChart tkExampleTitle tkToggleNavButton>
<DateTimeCategoricalAxis tkCartesianHorizontalAxis dateFormat="dd-MMM" labelFitMode="Rotate" labelRotationAngle="-1.2" labelTextColor="black"></DateTimeCategoricalAxis>
<LinearAxis tkCartesianVerticalAxis allowPan="false" allowZoom="false"></LinearAxis>
<LineSeries tkCartesianSeries selectionMode="DataPointMultiple" showLabels="true" [items]="distance" valueProperty="km_rec" categoryProperty="fecha">
<PointLabelStyle tkLineLabelStyle fontStyle="Bold" fillColor="#FC6060" textSize="12" textColor="White">
</PointLabelStyle>
</LineSeries>
<RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalLinesVisible="false" verticalStripLinesVisible="false" horizontalStripLinesVisible="true" >
</RadCartesianChartGrid>
</RadCartesianChart>
</GridLayout>
</StackLayout>
ngOnInit() {
this.initDataItems()
}
private initDataItems() {
this.checkedDistanceData();
}
checkedDistanceData() {
this.query(Config.storage.vehicleSelected, veh => {
this.query(moment().format('YYYY-MM-DD') + this.id_veh, data => {
if (data) {
this.setChartDistance(JSON.parse(data.value));
...
} else {
this.chartService();
...
}
});
};
});
chartService() {
this.httpGet(route (www.dis....),
data => {
this.setChartDistance(data);
this.changeDetector.detectChanges();
},
error => {
error...
}, null);
}
get getchartDistance() {
return distance;
}
setChartDistance(chart) {
this.distance = chart;
}
根据文档,您应该store your dates in milliseconds。
[最有可能您传递的是要序列化的日期对象,而在反序列化时,它丢失/获得了一些小时并转移到第二天。
[如果使用UTC
或本地时区对此更好,则可能需要运行一些测试(因为您正在使用时,可以使用moment.utc()
,然后以毫秒为单位获取它。]]