1
我有一個工作谷歌圖表,顯示在過去的24小時的數據,對於每一個小時(例如01:00至1時59分...等)的一個數據集。現在我試圖修改它,使其顯示過去24小時的數據,但在60分鐘內從當前時間(例如17:20到18:19 ...等)開始顯示數據。這是我對工作的代碼(https://jsfiddle.net/70boo2ss/):防止谷歌圖表X四捨五入日期時間列的軸線
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Hours');
data.addColumn('number', 'Col 1');
data.addColumn('number', 'Col 2');
data.addColumn('number', 'Percentage');
data.addRows([
[new Date(1454963244*1000),329,35,10.64],
[new Date(1454959644*1000),17,1,5.88],
[new Date(1454956044*1000),60,24,40.00],
[new Date(1454952444*1000),60,24,40.00],
[new Date(1454948844*1000),60,24,40.00],
[new Date(1454945244*1000),60,24,40.00],
[new Date(1454941644*1000),60,24,40.00],
[new Date(1454938044*1000),60,24,40.00],
[new Date(1454934444*1000),60,24,40.00],
[new Date(1454930844*1000),60,24,40.00],
[new Date(1454927244*1000),60,24,40.00],
[new Date(1454923644*1000),60,24,40.00],
[new Date(1454920044*1000),60,24,40.00],
[new Date(1454916444*1000),60,24,40.00],
[new Date(1454912844*1000),60,24,40.00],
[new Date(1454909244*1000),60,24,40.00],
[new Date(1454905644*1000),60,24,40.00],
[new Date(1454902044*1000),60,24,40.00],
[new Date(1454898444*1000),60,24,40.00],
[new Date(1454894844*1000),60,24,40.00],
[new Date(1454891244*1000),60,24,40.00],
[new Date(1454887644*1000),60,24,40.00],
[new Date(1454884044*1000),60,24,40.00],
[new Date(1454880444*1000),60,24,40.00],
]);
var formatter = new google.visualization.NumberFormat({
fractionDigits: 2,
suffix: '%'
});
formatter.format(data, 3);
var options = {
width: 1600,
height: 500,
backgroundColor: '#f1f1f1',
colors: ['#ff851b', '#03a9f4', '#8dc859'],
chartArea: {top:50, left:50, width: 1500},
hAxis: {format: 'h:mma', textStyle: { fontSize: '12' }, gridlines: { count: 24 }},
vAxes:[
{ },
{ gridlines: { color: 'transparent' }, minValue: 0, maxValue: 100, format: '#\'%\'', viewWindowMode : 'explicit', viewWindow:{
max:100,
min:0
}}],
series:[
{targetAxisIndex:0},
{targetAxisIndex:0},
{targetAxisIndex:1}
]
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart'));
chart.draw(data, options);
}
正如你可以的jsfiddle看到的,圖形化的數據被偏移到60分鐘的正確日期時間塊,但是橫軸開始於:00
如何使水平軸的啓動與圖形表示相同,而不是:00?