Data column(s) for axis #0 cannot be of type string in Google chart dashboard: What’s happening?
When you are creating a Google chart dashboard, have you ever gotten the Data column(s) for axis #0 cannot be of type string in Google chart dashboard error? If the error occurs and you don’t know how to tackle it, today’s blog will give you some solutions to deal with it. So, let’s try to find the most suitable way now!
How to fix the Data column(s) for axis #0 cannot be of type string in Google chart dashboard issue
As you know, if you want to draw and showcase a chart effectively, the data series have to be of type number and the x-axis data should be of type string. If you split a string into an array, all the elements of the array must be strings. For example, if you are using numeric data, it’s a good idea to change the line:
longArray.push(temp3[0]);
into:
longArray.push(parseFloat(temp3[0]));
If all your data is integers, use the following code:
longArray.push(parseInt(temp3[0], 10));
Moreover, you can also address the trouble by defining the column data types, such as:
var longArray = [
{label: 'Year', type: 'number'},
{label: 'Positive', type: 'number'},
{label: 'Negative', type: 'number'},
{label: 'Neutral', type: 'number'},
{label: 'Comments', type: 'string'},
{label: 'Status', type: 'string'},
{label: 'Score', type: 'number'}
];
When you input the data, you can do some crude type detection with the following code:
for(var i=0; i<temp.length; i++){
temp2 = temp[i].split(',');
if(temp2.length == 7){
for(var j=0; j<temp2.length;j++){
// this does nothing except make temp2[j] into a 1-element array
// temp3[0] === temp2[j], since you split on ',' already
temp3 = temp2[j].split(',');
if (temp3[0] == parseInt(temp3[0])) {
longArray.push(parseInt(temp3[0]));
}
else if (temp3[0] == parseFloat(temp3[0])) {
longArray.push(parseFloat(temp3[0]));
}
else {
longArray.push(temp3[0]);
}
}
}
}
If you have tried one of the methods above but the error still appears, you can combine the second and third methods to solve it.
Data column(s) for axis #0 cannot be of type string in Google chart dashboard – Ending
To sum up, we have given you some solutions to fix the trouble. We hope today’s blog is useful for you. If you have more effective methods or have any difficulties, don’t hesitate to share them with us by leaving your comment below. Thanks for reading and sharing. Have a great day!



