$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'api/v1/readings',
data: { get_param: 'readings' },
dataType: 'json',
success: function (data) {
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
var readings = data.readings;
function drawChart() {
var chartdata = new google.visualization.DataTable();
chartdata.addColumn('datetime', 'Time of Day');
chartdata.addColumn('number', 'Glucose Value');
chartdata.addRows([
readings.forEach(function(item){
let date = new Date(item.time);
{ [[`Date(${date.getYear()}, ${date.getMonth()}, ${date.getDate()})`], item.glucose_value]}
})
]);
So Im trying to pass a datestring from JSON readings
to google charts api but im receiving a an error for every row must be a null or array
.
the doc https://developers.google.com/chart/interactive/docs/datesandtimes#datestring
states that dates must be passed in quotes so how do i pass my Date
variable into the the string in order to parse it into a datetime object for the chart?
Your passing it as a object : {}
Take out the object notation and pass as [ [] ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.