Camden Narzt
Camden Narzt

Reputation: 2003

How can I access the currently selected time range in grafana more cleanly?

I'm embedding js into an html text panel, and would like to be able to reference the current time. However grafana is written in angular so there is a massive amount of abstraction and hiding of data; thus accessing the data I want has proven to be a mess.

The following works, but is probably all sorts of wrong to someone who knows angular at all. So is there a better way?

angular.element($(".grafana-menu-refresh > a")).scope().ctrl.timeSrv.timeRange()

Upvotes: 1

Views: 622

Answers (1)

ekarak
ekarak

Reputation: 618

Try:

var rng = angular.element('grafana-app').injector().get('timeSrv').timeRange();

Upvotes: 2

Related Questions