Here I'm getting an array of date/time epochs
ApiFactory.getTweetQuotes(the_ticker).then(function(data) {
// Create epoch array:
for (var i = 0; i < data.data.quotes.length; i++) {
vs.tweet_epochs.push(data.data.quotes[i].start_epoch);
}
console.log(vs.tweet_epochs);
initChart();
vs.loadingChart = true;
});
vs.tweet_epochs
looks like this consoled out:
I'm using Chartist and it's not printing out very pretty at the moment:
I found this answer here Convert UTC Epoch to local date with javascript however it just added 3 more 0
's to each epoch instead of convert them into dates.
If you need the Charist code:
var initChart = function() {
var data = {
labels: vs.tweet_epochs,
series: [
vs.tweet_vol
]
};
// Chart options:
var options = {
showPoint: true,
showArea: true,
lineSmooth: true,
fullWidth: true,
axisX: {
showGrid: false,
showLabel: true
},
axisY: {
offset: 40,
labelInterpolationFnc: function(value) {
return '$' + value;
}
}
};
var chart = new Chartist.Line('.ct-chart', data, options);
}
var date = new Date(TIME)
where TIME is the epoch time in MILIseconds, i.e, you should multiply by 1000 if you have a epoch time in seconds.
I don't know how Chartist handle Date objects, but you have a lot of methods to get all readeable parts of a date:
date.getDate date.getDay date.getFullYear date.getHours date.getMilliseconds date.getMinutes date.getMonth date.getSeconds date.getTime date.getTimezoneOffset date.getUTCDate date.getUTCDay date.getUTCFullYear date.getUTCHours date.getUTCMilliseconds date.getUTCMinutes date.getUTCMonth date.getUTCSeconds date.getYear date.setDate date.setFullYear date.setHours date.setMilliseconds date.setMinutes date.setMonth date.setSeconds date.setTime date.setUTCDate date.setUTCFullYear date.setUTCHours date.setUTCMilliseconds date.setUTCMinutes date.setUTCMonth date.setUTCSeconds date.setYear date.toDateString date.toGMTString date.toISOString date.toJSON date.toLocaleDateString date.toLocaleTimeString date.toTimeString date.toUTCString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With