This is my date-time format "2018.01.16 14:35:40". I am getting this data from the dynamodb database as a string. Now, I need to extract the date and time as a number in 2 different variables to draw a scatter plot using javascript. To do so, I need to format this format to Date(2018,01,16) and Date(2018,01,16,14,35) format. First one is for date row in the x-axis and the second one is for time row in the y-axis. I am not finding any javascript function to do that. I am trying to use toLocaleDateString and toLocaleTimeString functions for that. But those are not working so. Here is my code,
function onScan(err, data) {
if (err) {
document.getElementById('textarea').innerHTML += "Unable to scan the table: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
var clickDate, clickTime;
data.Items.forEach(function (iotButton) {
clickDate = iotButton.TimeStamp.toLocaleDateString(undefined, {
day: 'numeric',
month: 'numeric',
year: 'numeric'});
clickTime = iotButton.TimeStamp.toLocaleTimeString({
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
drawChart(clickDate, clickTime);
}
);
}
}
google.charts.load('current', {'packages': ['scatter']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(clickDate, clickTime) {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'Time');
data.addRows([
[clickDate, clickTime]
]);
var options = {
width: 700,
height: 500,
refreshInterval: 5,
chart: {
title: 'Rundzeiten nach Messzeitpunkt'
},
hAxis: {title: 'Date'},
vAxis: {title: 'Time'}
};
var chart = new google.charts.Scatter(document.getElementById('scatterchart_material'));
chart.draw(data, google.charts.Scatter.convertOptions(options));
}
Can anybody give me the hints or solutions how can I extract date and time individually to show it in the scatter plot? Thanks in advance.