mkandro
mkandro

Reputation: 27

Google visualization data table-getFilteredRows method

Im trying to filter column 'time' in visualization data table using getFilteredRows(filters) method.I provided column value with minimum and maximum values as,

var timesheet_dataTable = new google.visualization.DataTable(data, 0.6);
var time_filter = timesheet_dataTable.getFilteredRows([{column: 3, minValue: '2:28 PM', maxValue: '3:01 PM'}]);

and then created data view with setRows method to display the data but the table displayed without filtering the data.I checked with other column values and received proper output.So whether 'timeofday' data type is supported in this type of filters? Is there any other method to filter column based on time?

Update: This is the code for formatting and passing value to the visualization table.Value of variable startTime will be like '14:28:12'.

val datetimeStart: String = "Date(0,0,0,"
val datetimeEnd: String = ")"
val simpleDateTimeFormat = new SimpleDateFormat("HH,mm,ss")
Json.obj("v" -> JsString(datetimeStart + (simpleDateTimeFormat.format(tsl.startTime)).toString() + datetimeEnd))

before displaying in visualization table i have used formatter as:

var formatter_short1 = new google.visualization.DateFormat({pattern:'h:mm aa'});
formatter_short1.format(timesheet_dataTable,3); 

Upvotes: 0

Views: 4123

Answers (1)

asgallant
asgallant

Reputation: 26340

The "timeofday" data type is supported by the filter method, you just need to use it correctly:

// filter column 3 from 2:28PM to 3:01PM
var time_filter = timesheet_dataTable.getFilteredRows([{
    column: 3,
    minValue: [14, 28, 0, 0],
    maxValue: [15, 1, 0, 0]
}]);
var view = new google.visualization.DataView(timesheet_dataTable);
view.setRows(time_filter);

Make sure you are using the view you create to draw your chart, instead of the DataTable:

chart.draw(view, options);

[edit - example for filtering "datetime" type column]

// filter column 3 from 2:28PM to 3:01PM
var time_filter = timesheet_dataTable.getFilteredRows([{
    column: 3,
    minValue: new Date(0, 0, 0, 14, 28, 0, 0),
    maxValue: new Date(0, 0, 0, 15, 1, 0, 0)
}]);
var view = new google.visualization.DataView(timesheet_dataTable);
view.setRows(time_filter);

Upvotes: 2

Related Questions