我有一个使用 angularjs 和 highcharts 显示的日期线类型的图表。从 JSON 响应中检索日期值,例如 20120905(YYYYMMDD)。正如我在许多论坛中所读到的,我将日期转换为 UTC 格式以绘制图表。该图绘制正确,但我的 xaxis 显示所有日期时间值的 UTC 值,如 1,370G。
$scope.chartConfig = {
options: {
chart: {
type: 'line',
zoomType: 'x'
}
},
credits: {
enabled: false
},
series: [{
name: '% of Accounts',
data: outerSeries /* Contains the data similar to this. [[1368835200000, 2.9], [1371513600000, 0.5], [1374105600000, 1.94], [1376784000000, 1.44], [1379462400000, 1.18]] */
}],
title: {
text: tableTitle
},
xAxis: [{
labels: {format: '{value:%Y}' },
/*dateTimeLabelFormats:{
month:'%Y',
year:'%Y'
},*/
type:"datetime"
}],
yAxis: {title: {text: 'TestReport'}},
tooltip: {
formatter: function() {
var myDate = new Date(this.x);
var newDateMs = Date.UTC(myDate.getUTCFullYear(),myDate.getUTCMonth()-1,myDate.getUTCDate());
return '<b>'+ this.series.name +'</b><br/>'+Highcharts.dateFormat('%e. %b', newDateMs) +': '+ this.y;}
},
//xAxis: {currentMin: 0, currentMax: 10, minRange: 1, title:{text:'Time Period'}},
//xAxis: {ordinal:false,type:'datetime', dateTimeLabelFormats: { year: '%b%Y' }, title:{text:'Time Period'}},
loading: false
}
});