0

I am a newbie of Google charts. I am trying to change data type of a google chart data table column after this has been created. Searching for a solution over the internet I have bumped into this solution for a datetype column. May you generalize it in order to change a chosen data type column from number to string? I would like to change it so that I can visualize some strings in a number column, as you can see in the attached screenshot.

My trial is:

<script type="text/javascript">
function drawVisualization() {
$.get("delivery_pl_daily_test.csv", function(csvString) {
  // transform the CSV string into a 2-dimensional array
  var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});

  // this new DataTable object holds all the data
  var data = new google.visualization.arrayToDataTable(arrayData);

  var columns = [];
  for (var i = 0; i < data.getNumberOfColumns(); i++) {
    columns.push(i);
  }
  var view = new google.visualization.DataView(data);
  columns[0] = {
    calc: row,
    label: arrayData[0][0],
    type: 'string'
  };
  view.setColumns(columns);

Thanks in advance.

Drigoenter image description here

WhiteHat
  • 59,912
  • 7
  • 51
  • 133
fdrigo
  • 191
  • 1
  • 4
  • 14

1 Answers1

1

what you have looks close,
but calc should be a function,
that returns the value for the column.

the calc function receives the data table and current row as arguments.
here, I simply return the formatted value of the column.

columns[0] = {
  calc: function (dt, row) {
    return dt.getFormattedValue(row, 0);
  },
  label: arrayData[0][0],
  type: 'string'
};
WhiteHat
  • 59,912
  • 7
  • 51
  • 133