I am having problem in formatting the date column for Google Annotation chart. I am following this link https://developers.google.com/chart/interactive/docs/gallery/annotationchart
My Data for Annotation chart
var init_data = [["Week","A","A Title","A Annot","B","B Title","B Annot"],
["2022-05-01T18:30:00.000Z",10,"A","AAA",1984,"B","BBB"],
["2022-05-08T18:30:00.000Z",36,"A","AAA",150,"B","BBB"],
["2022-05-15T18:30:00.000Z",30,"A","AAA",199,"B","BBB"],
["2022-05-22T18:30:00.000Z",33,"A","AAA",184,"B","BBB"],
["2022-05-29T18:30:00.000Z",20,"A","AAA",161,"B","BBB"],
["2022-06-05T18:30:00.000Z",37,"A","AAA",172,"B","BBB"],
["2022-06-12T18:30:00.000Z",22,"A","AAA",151,"B","BBB"]]
I using below function to convert to mm/dd/yyyy format
function convertdate(date) {
date = new Date(date);
//console.log(date);
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString().padStart(2, '0');
let day = date.getDate().toString().padStart(2, '0');
return month + '/' + day + '/' + year;
}
Applying above function my data look like
var data = [['Week','A','A Title','A Annot','B','B Title','B Annot'],
['05/01/2022',10,'A','AAA',1984,'B','BBB'],
['05/08/2022',36,'A','AAA',150,'B','BBB'],
['05/15/2022',30,'A','AAA',199,'B','BBB'],
['05/22/2022',33,'A','AAA',184,'B','BBB'],
['05/29/2022',20,'A','AAA',161,'B','BBB'],
['06/05/2022',37,'A','AAA',172,'B','BBB'],
['06/12/2022',22,'A','AAA',151,'B','BBB']]
And I am passing above data to Array to DataTable function
var chart_data = google.visualization.arrayToDataTable(data);
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var options = {
displayAnnotations: true
};
chart.draw(chart_data, options);
It throws error in the browser(Google)
First column must contain date, or date and time.
I tried uing new Date() it gives me the date format like
Mon Oct 09 2023 00:00:00 GMT+0530 (India Standard Time) // This throws same error as well
How to format the date column for Google Annotation chart.