What can I change data.addcolumn first parameter in google sheets in order for me to be able to type in string?

Viewed 65

I commented out which line to change, and I want to change the first parameter in order to be able to change the number to a string.

var data = new google.visualization.DataTable();
      data.addColumn('number', 'Months since start of COVID 19 (November 2019 = 0 and June 2020 = 8)');
      //change line below
      data.addColumn('number', 'Recovered');
      data.addColumn('number', 'Death');
      data.addColumn('number', 'Known Cases');

      data.addRows([
        [1,  37.8, 80.8, 41.8],
        [2,  30.9, 69.5, 32.4],
        [3,  25.4,   57, 25.7],
        [4,  11.7, 18.8, 10.5],
        [5,  11.9, 17.6, 10.4],
        [6,   8.8, 13.6,  7.7],
        [7,   7.6, 12.3,  9.6],
        [8,   7.6, 12.3,  9.6]
      ]);
1 Answers

Considering this question was made a year ago and many commented a possible answer maybe you don't need this, but it may help you or someone else.

In order to make the first column type string just change the 'number' to 'string' like this.

var data = new google.visualization.DataTable();
  // v change below v
  data.addColumn('string', 'Months since start of COVID 19 (November 2019 = 0 and June 2020 = 8)');
  // ^ change above ^
  data.addColumn('number', 'Recovered');
  data.addColumn('number', 'Death');
  data.addColumn('number', 'Known Cases');

And to avoid problems with the data type just add ' ' or " ".

  data.addRows([
    ['1',  37.8, 80.8, 41.8],
    ['2',  30.9, 69.5, 32.4],
    ['3',  25.4,   57, 25.7],
    ['4',  11.7, 18.8, 10.5],
    ['5',  11.9, 17.6, 10.4],
    ['6',   8.8, 13.6,  7.7],
    ['7',   7.6, 12.3,  9.6],
    ['8',   7.6, 12.3,  9.6]
  ]);

Maybe this links would help anyone who needs help with more information about this.

https://developers.google.com/chart/interactive/docs/datatables_dataviews https://developers.google.com/chart/interactive/docs/quick_start https://developers.google.com/chart/interactive/docs/reference#DataTable_addColumn

Related