cjtsd
v1.0.8
Published
Compact JSON Time Series Data library
Downloads
3
Maintainers
Readme
Compact JSON Time Series Data library for Javascript
This is the Javascript library for handling Compact JSON Time Series Data (CJTSD) data in either client or server environment.
API documentation is available here.
Latest version can be found on npm and bower
The Java library can be found here.
Node.js
npm install cjtsd --save-dev
var cjtsd = require("cjtsd");
Browser
Something similar to this:
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://npmcdn.com/cjtsd/dist/cjtsd.min.js"></script>
Example - with C3.js
chart1 = c3.generate({
bindto: '#chart1',
data: {
x: 'time',
xFormat: '%Y-%m-%d %H:%M',
columns: [
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d %H:%M'
}
}
}
});
chart2 = c3.generate({
bindto: '#chart2',
data: {
x: 'time',
xFormat: '%Y-%m-%d',
columns: [
]
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
},
y: {
tick: {
format: d3.format(".2%")
}
},
y2:{
show: true,
tick: {
format: d3.format(",")
}
}
}
});
$.ajax(query)
.done(function(result){
if (!result.error){
var data = cjtsd.from(result);
var timeCol = cjtsd.getFormattedTimestamps(data, 'YYYY-MM-DD', 'time');
var dataCol = cjtsd.prepend(data.n, '# of something');
chart1.load({
columns: [
timeCol,
dataCol
]
});
}
});
$.ajax(query)
.done(function(result){
if (!result.error){
var data = cjtsd.from(result);
var timeCol = cjtsd.getFormattedTimestamps(data, 'YYYY-MM-DD', 'time');
var rateCol = cjtsd.prepend(data.a, 'Rate');
var totalCol = cjtsd.prepend(data.c, 'Count');
chart2.load({
columns: [
timeCol,
rateCol,
totalCol
],
axes: {
'Rate': 'y',
'Count': 'y2'
},
type: 'line',
types:{
'Count': 'bar'
}
});
}
});
Example - with Google DataTable
var offset = timeZoneOffsets[$("#mainForm select[name=timeZone]").val()];
var data = cjtsd.from(result);
var table = new google.visualization.DataTable();
table.addColumn('date', 'Time');
table.addColumn('number', '# of Play events');
cjtsd.setDataTableTimestampColumn(table, data, 0, 'YYYY-MM-DD HH:mm', offset);
cjtsd.setDataTableColumn(table, data.n, 1);