the error indicates that columns for the y-axis cannot be of type string.
the error is caused by the use of static method --> arrayToDataTable
arrayToDataTable tries to guess at what type of data is being passed to the method.
if it cannot determine the type, it defaults to string.
in the example of the "real" array, there is only one row of data.
and the only value it has to work with is null.
so it cannot properly determine the type and defaults to string.
you can see this result in the following working snippet...
google.charts.load('current', {
packages:['corechart']
}).then(function () {
var jsonData = [
['Día', 'Enfado', 'Irritabilidad','Dolor', 'Ansiedad', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'],
['28', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 180, 190, null]
];
var data = google.visualization.arrayToDataTable(jsonData);
for (var i = 0; i < data.getNumberOfColumns(); i++) {
console.log(i, data.getColumnType(i));
}
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
instead, you will need to build the data table manually,
setting the specific column type for each column.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Día'); // <-- x-axis - string
data.addColumn('number', 'Enfado'); // <-- y-axis - number
data.addColumn('number', 'Irritabilidad'); // <-- y-axis - number
...
but we can build the data table dynamically,
based on the json data received.
var jsonData = [
['Día', 'Enfado', 'Irritabilidad','Dolor', 'Ansiedad', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'],
['28', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 180, 190, null]
];
var data = new google.visualization.DataTable();
jsonData.forEach(function (row, indexRow) {
if (indexRow === 0) {
row.forEach(function (column, indexCol) {
if (indexCol === 0) {
data.addColumn('string', column);
} else {
data.addColumn('number', column);
}
});
} else {
data.addRow(row);
}
});
see following working snippet...
google.charts.load('current', {
packages:['corechart']
}).then(function () {
var jsonData = [
['Día', 'Enfado', 'Irritabilidad','Dolor', 'Ansiedad', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'],
['28', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 180, 190, null]
];
var data = new google.visualization.DataTable();
jsonData.forEach(function (row, indexRow) {
if (indexRow === 0) {
row.forEach(function (column, indexCol) {
if (indexCol === 0) {
data.addColumn('string', column);
} else {
data.addColumn('number', column);
}
});
} else {
data.addRow(row);
}
});
var options = {
chartArea: {
left: 64,
top: 48,
right: 32,
bottom: 64,
height: '100%',
width: '100%'
},
height: '100%',
legend: {
position: 'none'
},
width: '100%'
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart'));
chart.draw(data, options);
});
html, body {
height: 100%;
margin: 0px 0px 0px 0px;
overflow: hidden;
padding: 0px 0px 0px 0px;
}
#chart {
height: 100%;
min-height: 400px;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>