Modify value of a metric (keen-dataviz.js)
Manually modify the value of a metric visualization
by keen
HTML
<link rel="stylesheet" href="https://d26b395fwzu5fz.cloudfront.net/keen-dataviz-1.1.3.css">
<script src="https://d26b395fwzu5fz.cloudfront.net/keen-dataviz-1.1.3.js"></script>
<div id="chart"></div>
JavaScript
// Create and configure the chart instance
var chart = new Keen.Dataviz()
.el("#chart")
.title("Revenue per month")
.chartOptions({ prefix: "$" })
.height(240)
.prepare();
// Parses raw data into a new internal Dataset instance
chart
.parseRawData({ result: 4932212 });
// Internal Dataset looks something like this:
/*
[
[ 'index', 'value' ],
[ 'result', 4932212 ]
]
*/
chart
.call(function(){
// Modify internal Dataset instance
this.dataset.updateColumn(1, function(value, index, column){
// Divide each value in column 1 by 100
return value / 100;
});
})
.render();
// Internal Dataset now looks like this:
/*
[
[ 'index', 'value' ],
[ 'result', 49322.12 ]
]
*/