Charts.newDataTable() not working with Dates
From within a Google Ads script, I'm trying to create a basic line chart as described here: https://developers.google.com/apps-script/reference/charts/line-chart-builder
The data that I'm looking to chart is Date X Clicks.
I'm able to generate the chart with my data from Google Ads, however, Dates are being formatted as Strings and not actual dates within the chart which is causing other issues.
For example, this code will work with my data but formats the dates as strings within the chart:
var dataBuilder = Charts.newDataTable(); dataBuilder.addColumn(Charts.ColumnType.STRING, 'Date'); dataBuilder.addColumn(Charts.ColumnType.NUMBER, 'Clicks');
When I try this code, it does not work:
var dataBuilder = Charts.newDataTable(); dataBuilder.addColumn(Charts.ColumnType.DATE, 'Date'); dataBuilder.addColumn(Charts.ColumnType.NUMBER, 'Clicks');
I have tried to convert the date data from this: ["2019-09-27",75],["2019-09-29",102],["2019-9-30",112]
To something like this: ["new Date(2019,9,27)",75],["new Date(2019,9,29)",102],["new Date(2019,9,30)",112]
Based on the documentation that I found here: https://developers.google.com/chart/interactive/docs/datesandtimes
But that does not seem to work.
Any suggestions?