【发布时间】:2021-09-01 14:13:16
【问题描述】:
所以我目前正在尝试解决 Google 图表的问题。我正在绘制一个图表,在 Y 轴上显示数值,在 X 轴上显示日期。我希望日期根据指定的时区进行调整。为此,我使用 Google 图表中的 DateFormatter 对象,提供模式和时区,如下所示:
var dateFormatter = new google.visualization.DateFormat({
timeZone: _timeZone, //timezone
pattern: $scope.selectedResolution.pattern
});
pattern 属性接收一个包含格式字符串的字符串,timeZone 接收一个表示与时区偏移有关的小时数的值(例如,-4、-5 等)。
我像这样格式化图表值:
dateFormatter.format($scope.data, 0);
因为“0”列是我有我的日期的列。
然后我绘制图表,标准的东西:
chart = new google.visualization.ComboChart(document.getElementById(chart_name));
//generateTicks($scope.data, options);
chart.draw($scope.data, options);
问题是,X 轴上显示的值没有任何格式,无论是格式还是时区。
如上图所示,X 轴显示“13:00”,在这种特殊情况下,它应该显示“15:00”。
我还检查了我为图表提供的数据,看看格式化程序是否真的对数据本身进行了任何工作,并且它似乎工作正常:
另外,这是我的图表选项供参考:
var series = {}, firstSerie, row, title, tempRows = [];
// Create the data table
series[0] = {targetAxisIndex: 0, color: '#3182BD'};
series[1] = {color: '#FF7F00', type: 'line'};
options = {
tooltip: {isHtml: true},
titleTextStyle: {fontSize: 12, bold: false},
isStacked: false,
backgroundColor: 'transparent',
legend: {position: 'none'},
height: 300,
pointSize: 1,
series: series,
vAxes: {
// Adds titles to each axis.
0: {
textStyle: {color: $scope.widgetOptions.text_color || '#333333'},
format: $scope.vLabel === '%' ? '#\'%\'' : generateVerticalAxisPattern() + $filter('trustedHtml')($scope.vLabel),
minValue: 0,
gridlines: {
color: 'transparent'
}
}
},
hAxis: {
//title: graphLegend,
textStyle: {color: $scope.widgetOptions.text_color || '#333333'},
titleTextStyle: {color: $scope.widgetOptions.text_color || '#333333'},
viewWindows: {
min: moment().subtract(24, 'hours'),
max: moment()
},
gridlines: {
color: 'transparent',
units: {
hours: {format: ['HH:mm', 'ha']}
},
count: -1
},
minorGridlines: {
count: 0
}
},
vAxis: {
viewWindowMode: 'maximized',
viewWindow: {
min: $scope.widgetOptions.lower_limit
}
},
animation: {
duration: 500,
easing: 'out'
}
};
那么,有人知道发生了什么吗?我正在使用 angularjs 顺便说一句。 提前致谢
【问题讨论】:
标签: javascript angularjs charts google-visualization