Keen.Dataviz state control

Toggle loading and error states for instances of Keen.Dataviz

by keen

HTML

<script src="https://d26b395fwzu5fz.cloudfront.net/3.4.0/keen.min.js?date=2016-02-17"></script>
<div id="chart"></div>

JavaScript

var chart = new Keen.Dataviz()
        .el(document.getElementById("chart"))
        .height(300)
        .prepare(); // clear DOM element and start spinner

function setMessage(){
    // Display a custom error message
    chart.error("Randos: " + getRando());
}

function getRando(){
    return Math.floor((Math.random() * 10) + 1);
}

setTimeout(function(){
    setMessage();
    setInterval(setMessage, 1000);
}, 2000);