I am trying to utilize the Google Chart API to create a line chart. I need to retrieve data through an AJAX method and then set this data to the chart using a JavaScript JSON array. However, I am encountering difficulties with the datetime format within this process. Furthermore, the data obtained from AJAX is in string format that is generated from PHP. I am parsing this returned string into a JSON array which will be used as the chart data.
v1 = '{"Date(2023, 1, 1, 20, 00, 00)", ... }'; # returned string from AJAX
v1 = jQuery.parseJSON(v1);
data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time');
data.addColumn({...something else...});
data.addRows(v1);
options = { ... };
chart = new google.visualization.LineChart(document.getElementById('linechart_material'));
chart.draw(data, options);
When attempting to use the
Date(year, month, day, hour, minute, second)
constructor (referencing theGoogle "Date String Representation" method) as the first element of the v1
array, I encounter the following error message in the console: Unhandled Promise Rejection: Error: Type mismatch. Value Date(2023, 1, 1, 20, 00, 00) does not match type datetime in column index 0
What is the correct way to prepare datetime values in a JSON array for use with the Google Chart API?