Developing Datasource

Hi there,

I wanna build my own datasource to show data in a grafana graph. Now, I testing de fake simple json in grafana, to figure out how the things work behind the scenes. I have this code:

query(options) {
    var query = this.buildQueryParameters(options);
    query.targets = query.targets.filter(t => !t.hide);

    if (query.targets.length <= 0) {
      return this.q.when({data: []});
    }

    console.log('query Return: ');
    console.log(this.doRequest({url: this.url + '/query',data: query,method: 'POST'}));
    console.log('\n');

    var teste = this.doRequest({
      url: this.url + '/query',
      data: query,
      method: 'POST'
    });
 
    console.log('teste Return: ');
    console.log(teste);
    console.log('\n');
    return teste;
  }

And, I receive that return :
Sem título

How can I acess the teste.$$state.value.data[“0”].datapoints[“0”] for example?

If I tried to acess teste or teste.$$state, thats ok. But wheh I try teste.$$state.pur or any atributtes in the teste.$$state tree I got an undefined response.

You need to read up on promises, you get the result in the promise then handler

1 Like