keen / keen-js

https://keen.io/ JavaScript SDKs. Track users and visualise the results. Demo http://keen.github.io/keen-dataviz.js/
MIT License
578 stars 143 forks source link

HowTo: disable drawing when no results from Keen.Query? #238

Closed lgrijsen closed 9 years ago

lgrijsen commented 9 years ago

I succesfully get results from Keen.Query, but in some circumstances with a certain set of filters, there are no results from the database (which is correct), but how to prevent drawing (client.draw) in that case?

There is a textual message ('No results to visualize'), but how to alter that, or better, to prevent?

dustinlarimer commented 9 years ago

Hey, @lgrijsen - great question! You could use client.run(query, callback) and build the viz manually if you like:

var chart = new Keen.Dataviz()
  .chartType("barchart")
  .height(400)
  .prepare(); // start spinner

client.run(query, function(err, res){
  if (err) {
    chart.error(err.message);
  }
  else if (!res.result.length) {
    chart.error("No results to visualize");
  }
  else {
    chart
      .parseRequest(this)
      .title("Visualizing " + res.result.length + " results");
      .render();
  }
});