简体   繁体   English

在Google图表中过滤日期,然后过滤时间

[英]Filtering Dates and then Time in Google Charts

I'm trying to use ChartRangeFilter to filter the dates and then filter it at time level. 我正在尝试使用ChartRangeFilter过滤日期,然后在时间级别对其进行过滤。 For Example: Timestamp 例如:时间戳
05/03/2016 12:00:19 05/03/2016 12:00:19
05/03/2016 12:01:31 05/03/2016 12:01:31
05/03/2016 12:02:43 2016年5月3日12:02:43
05/03/2016 12:32:01 05/03/2016 12:32:01
05/03/2016 12:33:14 05/03/2016 12:33:14
06/03/2016 11:50:42 06/03/2016 11:50:42
06/03/2016 11:51:57 2016/03/06 11:51:57
06/03/2016 11:53:11 06/03/2016 11:53:11
06/03/2016 11:54:25 06/03/2016 11:54:25
06/03/2016 11:55:39 2016/03/06 11:55:39
07/03/2016 15:43:50 2016年7月3日15:43:50
07/03/2016 15:45:02 2016年7月3日15:45:02
07/03/2016 15:46:14 2016年7月3日15:46:14
07/03/2016 15:47:26 2016年7月3日15:47:26

So after setting the date for only 5/03/2016, I want to filter the time from 12:00 to 12:15. 因此,在将日期设置为仅5/03/2016之后,我想将时间从12:00过滤为12:15。 So in the chart, it'll only plot first three values. 因此,在图表中,它将仅绘制前三个值。
Tried this and it didn't work. 试过这个并没有用。

chartDateFilter = new google.visualization.ControlWrapper({
'controlType' : 'ChartRangeFilter',
'containerId' : 'chartDateFilter_id',
'state' : {
    'range' : {
        'start' : '1',
        'end'   : '31'
               }
            },
'options' : {
    'filterColumnLabel':'TimeStamp'
}
});

chartTimeFilter = new google.visualization.ControlWrapper({
'controlType' : 'ChartRangeFilter',
'containerId' : 'chartFilter_id',
'state' : {
    'range' : {
    'start' : '00:00',
    'end'   : '23:59'
}
},
'options' : {
    'filterColumnLabel':'TimeStamp'
            }
});

In order to have two separate filters, you would need two separate columns in the data. 为了拥有两个单独的过滤器,您需要在数据中使用两个单独的列。
But the ChartRangeFilter handles both date and time, so no need... ChartRangeFilter处理日期和时间,所以不需要......

In addition, the values set for range.start and range.end should be datetime values. 此外,设置的值range.startrange.end应该是日期时间值。

See following example... 见下面的例子......

 google.charts.load('44', { callback: drawChart, packages: ['controls', 'corechart'] }); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('date', 'TimeStamp'); data.addColumn('number', 'Value'); data.addRow([new Date('05/03/2016 12:00:19'), 0]); data.addRow([new Date('05/03/2016 12:01:31'), 1]); data.addRow([new Date('05/03/2016 12:02:43'), 2]); data.addRow([new Date('05/03/2016 12:32:01'), 3]); data.addRow([new Date('05/03/2016 12:33:14'), 4]); data.addRow([new Date('06/03/2016 11:50:42'), 5]); data.addRow([new Date('06/03/2016 11:51:57'), 6]); data.addRow([new Date('06/03/2016 11:53:11'), 7]); data.addRow([new Date('06/03/2016 11:54:25'), 8]); data.addRow([new Date('06/03/2016 11:55:39'), 9]); data.addRow([new Date('07/03/2016 15:43:50'), 10]); data.addRow([new Date('07/03/2016 15:45:02'), 11]); data.addRow([new Date('07/03/2016 15:46:14'), 12]); data.addRow([new Date('07/03/2016 15:47:26'), 13]); var control = new google.visualization.ControlWrapper({ controlType: 'ChartRangeFilter', containerId: 'control_div', state: { range: { start: new Date('05/03/2016 12:00:00'), end: new Date('05/03/2016 12:15:00') } }, options: { filterColumnLabel: 'TimeStamp' } }); var chart = new google.visualization.ChartWrapper({ chartType: 'LineChart', containerId: 'chart_div' }); var dash = new google.visualization.Dashboard(document.getElementById('dashboard')); dash.bind([control], [chart]); dash.draw(data); } 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="dashboard"> <div id="chart_div"></div> <div id="control_div"></div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM