c3 - JSON data with timeseries and date filter
Display only the first of the month
HTML
<script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script>
<link rel="stylesheet" href="https://rawgit.com/masayuki0812/c3/master/c3.css">
<script src="http://gabelerner.github.io/canvg/canvg.js"></script>
<script src="https://gabelerner.github.io/canvg/StackBlur.js"></script>
<script src="https://gabelerner.github.io/canvg/rgbcolor.js"></script>
<div id="chart"></div>
<canvas id='canvas' width="1000px" height="600px"/>
JavaScript
var chart = c3.generate({
data: {
json: [{
date: '2014-01-01',
upload: 200,
download: 200,
total: 400
}, {
date: '2014-01-02',
upload: 100,
download: 300,
total: 400
}, {
date: '2014-02-01',
upload: 300,
download: 200,
total: 500
}, {
date: '2014-02-02',
upload: 400,
download: 100,
total: 500
}],
keys: {
x: 'date',
value: ['upload', 'download']
}
},
axis: {
x: {
type: 'timeseries',
tick: {
format: function (x) {
if (x.getDate() === 1) {
return x.toLocaleDateString();
}
}
}
}
}
});
canvg('canvas', document.getElementById('chart').innerHTML);
// the canvas calls to output a png
var canvas = document.getElementById("canvas");
var img = canvas.toDataURL("image/png");