Access timepicker range from within visualization plugin

(Nathan) #1

I am trying to access the queried date range from within a plugin, so that I can do calculations based on the length of time being queried. Is there a way to do this?

For example, I may have an aggregated sum of hits and I want to calculate the average number of hits per second and display that number in the visualization.

(Lukas Olson) #2

Hi Nathan!

If you are using Angular, then timefilter is an available service.

Here's where the timefilter is defined:

And here's an example of how to use it:

I'd suggest using timefilter.getBounds() to accomplish what you're trying to do.

(Nathan) #3

Thank you very much! I was able to get the length of time with:
var ms = Date.parse($scope.timefilter.getBounds().max._d) - Date.parse($scope.timefilter.getBounds().min._d);

(system) #4